//
//  KATTableView.m
//  KATFramework
//
//  Created by Kantice on 15/8/4.
//  Copyright (c) 2015年 KatApp. All rights reserved.
//

#import "KATTableView.h"

#import "KATTableBuilder.h"




@interface KATTableView ()

//滚动视图
@property(nonatomic,retain) UIScrollView *scrollView;

//远程图片更新定时器
@property(nonatomic,retain) NSTimer *remoteImageUpdateTimer;

//显示的cell数组
@property(nonatomic,retain) KATArray<__kindof KATTableCell *> *cellArray;

//cell数据数组
@property(nonatomic,retain) KATArray<__kindof KATTableCellData *> *dataArray;


@end



@implementation KATTableView


+ (instancetype)tableWithFrame:(CGRect)frame
{
    KATTableView *table=[[[self alloc] init] autorelease];
        
    table.frame=frame;
    table.scrollView=[[[UIScrollView alloc] init] autorelease];
    table.scrollView.frame=CGRectMake(0, 0, frame.size.width, frame.size.height);
    table.scrollView.alwaysBounceVertical=YES;
    [table addSubview:table.scrollView];
    table.scrollView.delegate=table;
    table.isShownScrollIndicator=NO;
    table.builder=nil;
    table.eventDelegate=nil;
    table.remoteImageUpdateTimer=nil;
    table.isRemoteImageUpdateTimerWorking=NO;
    table.remoteImageUpdateInterval=0.5;
    table.cellRemoveTime=0.6;
    table.pages=0;
    table.isTapTableToRestoreCells=YES;
    table.backgroundColor=[UIColor clearColor];
    table.scrollView.backgroundColor=[UIColor clearColor];
    table.cellsDisplayMax=TABLE_CELLS_DISPLAY_MAX;
    table.cellsDisplayTimes=TABLE_CELLS_DISPLAY_TIMES;
    table.cellHeight=TABLE_CELL_HEIGHT_DEFAULT;
    table.cellMarginTop=0;
    table.cellMarginBottom=0;
    table.cellMarginInner=0;
    table.movingDirection=TABLE_MOVE_STOP;
    table.changeDirection=TABLE_CHANGE_NONE;
    table.cellWidth=frame.size.width;
    table.scrollSpeed=0.0;
    table.highScrollSpeed=5.0;
    table.startPositionY=0.0;
    table.endPositionY=0.0;
    table.bottomInsertHeight=0.0;
    table.cellOffset=0;
    table.displayOffset=0;
    table.cellsRemoved=0;
    table.tapedCellNum=-1;
    table.currentPosition=CGPointMake(0.0, 0.0);
    table.displayBottomCellNum=-1;
    table.displayTopCellNum=-1;
    table.editCellNum=-1;
    table.state=TABLE_STATE_INIT;
    table.reloadTimes=0;
    table.cellArray=nil;
    table.dataArray=nil;
    table.backBgColor=[UIColor clearColor];
    table.midBgColor=[UIColor clearColor];
    table.faceBgColor=[UIColor clearColor];
    table.hasBackBgColor=NO;
    table.hasMidBgColor=NO;
    table.hasFaceBgColor=NO;
    table.hasImage=NO;
    table.hasImage2=NO;
    table.hasImage3=NO;
    table.imageCorner=0;
    table.image2Corner=0;
    table.image3Corner=0;
    table.hasTitle=NO;
    table.hasContent=NO;
    table.hasRichTitle=NO;
    table.hasRichContent=NO;
    table.hasRichLabel=NO;
    table.hasBadge=NO;
    table.hasBadgeBorder=NO;
    table.badgeBorderWidth=0.5f;
    table.hasText=NO;
    table.hasLabel1=NO;
    table.hasLabel2=NO;
    table.hasLabel3=NO;
    table.hasLabel4=NO;
    table.hasLabel5=NO;
    table.hasCacheImage=NO;
    table.isRemoteImage=NO;
    table.cacheImage=nil;
    table.buttonLineWidth=1.5f;
    table.hasButtonClickAnimation=YES;
    table.hasButton1=NO;
    table.hasButton2=NO;
    table.hasButton3=NO;
    table.hasSpButton=NO;
    table.button1Color=nil;
    table.button2Color=nil;
    table.button3Color=nil;
    table.button1Type=KATButtonTypeNone;
    table.button2Type=KATButtonTypeNone;
    table.button3Type=KATButtonTypeNone;
    table.button1Scale=1.0;
    table.button2Scale=1.0;
    table.button3Scale=1.0;
    table.line1Color=nil;
    table.line2Color=nil;
    table.topLineColor=nil;
    table.bottomLineColor=nil;
    table.hasLine1=NO;
    table.hasLine2=NO;
    table.hasTopLine=NO;
    table.hasBottomLine=NO;
    table.titleColor=[UIColor blackColor];
    table.titleFont=[UIFont systemFontOfSize:15];
    table.titleLines=1;
    table.titleLineBreak=NSLineBreakByWordWrapping|NSLineBreakByTruncatingTail;
    table.titleAlignment=NSTextAlignmentLeft;
    table.textColor=[UIColor blackColor];
    table.textFont=[UIFont systemFontOfSize:13];
    table.textAlignment=NSTextAlignmentLeft;
    table.textBgColor=[UIColor clearColor];
    table.hasTextBorder=NO;
    table.textBorderWidth=1.0f;
    table.textBorderColor=[UIColor grayColor];
    table.textBorderCorner=0.0;
    table.textCanEdit=NO;
    //table.textDelegate=nil;
    table.contentColor=[UIColor grayColor];
    table.contentFont=[UIFont systemFontOfSize:13];
    table.contentLines=1;
    table.contentAlignment=NSTextAlignmentLeft;
    table.contentLineBreak=NSLineBreakByWordWrapping|NSLineBreakByTruncatingTail;
    table.label1Color=nil;
    table.label1Font=nil;
    table.label1Lines=1;
    table.label1Alignment=NSTextAlignmentLeft;
    table.label1LineBreak=NSLineBreakByWordWrapping|NSLineBreakByTruncatingTail;
    table.label2Color=nil;
    table.label2Font=nil;
    table.label2Lines=1;
    table.label2Alignment=NSTextAlignmentLeft;
    table.label2LineBreak=NSLineBreakByWordWrapping|NSLineBreakByTruncatingTail;
    table.label3Color=nil;
    table.label3Font=nil;
    table.label3Lines=1;
    table.label3Alignment=NSTextAlignmentLeft;
    table.label3LineBreak=NSLineBreakByWordWrapping|NSLineBreakByTruncatingTail;
    table.label4Color=nil;
    table.label4Font=nil;
    table.label4Lines=1;
    table.label4Alignment=NSTextAlignmentLeft;
    table.label4LineBreak=NSLineBreakByWordWrapping|NSLineBreakByTruncatingTail;
    table.label5Color=nil;
    table.label5Font=nil;
    table.label5Lines=1;
    table.label5Alignment=NSTextAlignmentLeft;
    table.label5LineBreak=NSLineBreakByWordWrapping|NSLineBreakByTruncatingTail;
    table.badgeFont=nil;
    table.badgeTextColor=[UIColor whiteColor];
    table.badgeBgColor=KCOLOR_RED;
    table.badgeBorderColor=[UIColor clearColor];
    table.badgeCorner=0.0;
    table.badgeLines=1;
    table.badgeAlignment=NSTextAlignmentCenter;
    table.badgeLineBreak=NSLineBreakByWordWrapping|NSLineBreakByTruncatingTail;
    table.richTitleStyle=[KATTextStyle textStyle];
    table.richContentStyle=[KATTextStyle textStyle];
    table.richLabelStyle=[KATTextStyle textStyle];
    
    table.noneDataTipsLabel=nil;
    table.noneDataTipsTextColor=[UIColor grayColor];
    table.noneDateTipsAlignment=NSTextAlignmentCenter;
    table.noneDateTipsLineBreak=NSLineBreakByWordWrapping|NSLineBreakByTruncatingTail;
    table.noneDateTipsTextFont=[UIFont systemFontOfSize:18];
    table.noneDateTipsLines=1;
    table.strNoneDataTips=nil;
    table.canMoveLeft=NO;
    table.canMoveRight=NO;
    table.canPanCell=NO;
    table.leftMovingDst=0.0;
    table.rightMovingDst=0.0;
    table.leftMovingFlexibleDst=20.0;
    table.rightMovingFlexibleDst=20.0;
    table.movingTime=1.0/frame.size.width;
    table.backButtonLineWidth=2.0f;
    table.hasBackButtonClickAnimation=NO;
    table.hasBackButton1=NO;
    table.hasBackButton2=NO;
    table.hasBackButton3=NO;
    table.hasBackButton4=NO;
    table.hasBackButton5=NO;
    table.hasBackButton6=NO;
    table.hasBackButton7=NO;
    table.hasBackLabel=NO;
    table.backButton1Color=nil;
    table.backButton2Color=nil;
    table.backButton3Color=nil;
    table.backButton4Color=nil;
    table.backButton5Color=nil;
    table.backButton6Color=nil;
    table.backButton7Color=nil;
    table.backButton1Type=KATButtonTypeNone;
    table.backButton2Type=KATButtonTypeNone;
    table.backButton3Type=KATButtonTypeNone;
    table.backButton4Type=KATButtonTypeNone;
    table.backButton5Type=KATButtonTypeNone;
    table.backButton6Type=KATButtonTypeNone;
    table.backButton7Type=KATButtonTypeNone;
    table.backButton1Scale=1.0;
    table.backButton2Scale=1.0;
    table.backButton3Scale=1.0;
    table.backButton4Scale=1.0;
    table.backButton5Scale=1.0;
    table.backButton6Scale=1.0;
    table.backButton7Scale=1.0;
    table.hasCellTapEvent=YES;
    table.hasCellLongPressEvent=NO;
    table.hasFaceLayerTapEvent=NO;
    table.hasMidLayerTapEvent=NO;
    table.hasBackLayerTapEvent=NO;
    table.hasImageTapEvent=NO;
    table.hasImage2TapEvent=NO;
    table.hasImage3TapEvent=NO;
    table.hasTitleTapEvent=NO;
    table.hasContentTapEvent=NO;
    table.hasRichTitleTapEvent=NO;
    table.hasRichContentTapEvent=NO;
    table.hasRichLabelTapEvent=NO;
    table.hasLabel1TapEvent=NO;
    table.hasLabel2TapEvent=NO;
    table.hasLabel3TapEvent=NO;
    table.hasLabel4TapEvent=NO;
    table.hasLabel5TapEvent=NO;
    table.hasButton1TapEvent=NO;
    table.hasButton2TapEvent=NO;
    table.hasButton3TapEvent=NO;
    table.hasBackButton1TapEvent=NO;
    table.hasBackButton2TapEvent=NO;
    table.hasBackButton3TapEvent=NO;
    table.hasBackButton4TapEvent=NO;
    table.hasBackButton5TapEvent=NO;
    table.hasBackButton6TapEvent=NO;
    table.hasBackButton7TapEvent=NO;
    table.hasBackLabelTapEvent=NO;
    table.hasBadgeTapEvent=NO;
    table.tapedBgColor=[UIColor blueColor];
    table.tapedButtonColor=[UIColor whiteColor];
    table.tapedTextColor=[UIColor whiteColor];
    table.isTapToChangeFaceLayerColor=NO;
    table.tapedFaceLayerColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.06f];
    table.tapChangeColorTime=0.3f;
    table.backLabelColor=[UIColor blackColor];
    table.backLabelFont=[UIFont systemFontOfSize:15];
    table.backLabelLines=1;
    table.backLabelLineBreak=NSLineBreakByWordWrapping|NSLineBreakByTruncatingTail;
    table.backLabelAlignment=NSTextAlignmentLeft;
    table.lastPosition=CGPointMake(0, 0);
    table.currentPosition=CGPointMake(0, 0);
    table.hasPullHeader=NO;
    table.pullHeader=nil;
    table.pullHeaderHeight=TABLE_HEADER_HEIGHT_DEFAULT;
    table.hasPushFooter=NO;
    table.pushFooter=nil;
    table.pushFooterHeight=TABLE_HEADER_HEIGHT_DEFAULT;
    
    table.queueImage=dispatch_queue_create([[NSString stringWithFormat:@"table_queue_image_%lu",(unsigned long)[table hash]] cStringUsingEncoding:NSUTF8StringEncoding], DISPATCH_QUEUE_CONCURRENT);
    table.queueImage2=dispatch_queue_create([[NSString stringWithFormat:@"table_queue_image2_%lu",(unsigned long)[table hash]] cStringUsingEncoding:NSUTF8StringEncoding], DISPATCH_QUEUE_CONCURRENT);
    table.queueImage3=dispatch_queue_create([[NSString stringWithFormat:@"table_queue_image3_%lu",(unsigned long)[table hash]] cStringUsingEncoding:NSUTF8StringEncoding], DISPATCH_QUEUE_CONCURRENT);
    
    table.scrollView.contentSize=CGSizeMake(frame.size.width, frame.size.height);
    
    return table;
}



//初始化cells和下拉、上推控件
- (void)initTable
{
    _state=TABLE_STATE_INIT;
    
    _isScrollDisabled=NO;
    
    //滚动指示器
    _scrollView.showsVerticalScrollIndicator=_isShownScrollIndicator;
    _scrollView.showsHorizontalScrollIndicator=NO;
    
    //初始化下拉控件
    if(_hasPullHeader)
    {
        self.pullHeader=[KATStandardTableHeader tableHeaderWithHeight:_pullHeaderHeight andScrollView:_scrollView];
        _pullHeader.eventDelegate=self;
        
        [_pullHeader initHeader];
    }
    
    
    //初始化无数据提示信息
    if(_hasNoneDataTips)
    {
        self.noneDataTipsLabel=[[[UILabel alloc] init] autorelease];
        self.noneDataTipsLabel.frame=_noneDataTipsFrame;
        self.noneDataTipsLabel.textAlignment=_noneDateTipsAlignment;
        self.noneDataTipsLabel.font=_noneDateTipsTextFont;
        self.noneDataTipsLabel.textColor=_noneDataTipsTextColor;
        self.noneDataTipsLabel.backgroundColor=[UIColor clearColor];
        self.noneDataTipsLabel.numberOfLines=_noneDateTipsLines;
        self.noneDataTipsLabel.lineBreakMode=_noneDateTipsLineBreak;
        self.noneDataTipsLabel.text=_strNoneDataTips;
    }
    
    
    //初始化cells
    self.cellsDisplayCount=(int)(self.scrollView.bounds.size.height/(self.cellHeight+self.cellMarginInner)+1.5);
    self.cellsDisplayMax=self.cellsDisplayCount*self.cellsDisplayTimes;
    
    if(_cellsDisplayMax%2==1)//奇数变偶数，防止排序动画时可能出现的显示bug
    {
        _cellsDisplayMax++;
    }
    
    self.cellArray=[KATArray arrayWithCapacity:_cellsDisplayMax];
    
    for(int i=0;i<_cellsDisplayMax;i++)
    {
        KATTableCell *cell=[KATTableCell cell];
        cell.tableView=self;
        cell.num=i;
        cell.tag=i;
        
        cell.frame=CGRectMake(-_cellWidth*2, -_cellHeight*5-100.0, _cellWidth, _cellHeight);
        
        //设置按钮点击事件
        UITapGestureRecognizer *singleTap=nil;
        
        //cell点击事件
        if(_hasCellTapEvent)//if(_canMoveLeft || _canMoveRight || (_hasText && _textCanEdit) )
        {
            cell.userInteractionEnabled=YES;
            
            singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellTap:)];
            singleTap.numberOfTapsRequired=1;//点击次数
            [cell addGestureRecognizer:singleTap];//添加点击事件
            [singleTap release];
        }
        
        //cell长按事件
        if(_hasCellLongPressEvent)
        {
            UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(cellLongPress:)];
            [cell addGestureRecognizer:longPress];
            [longPress release];
        }
        
        
        //背面层
        cell.backLayer=[[[UIView alloc] init] autorelease];
        cell.backLayer.frame=CGRectMake(0, 0, cell.bounds.size.width, cell.bounds.size.height);
        cell.backLayer.backgroundColor=_backBgColor;
        [cell addSubview:cell.backLayer];
        
        if(_hasBackLayerTapEvent)//点击事件
        {
            singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backLayerTap:)];
            singleTap.numberOfTapsRequired=1;//点击次数
            [cell.backLayer addGestureRecognizer:singleTap];//添加点击事件
            [singleTap release];
        }
        
        if(_canMoveLeft || _canMoveRight)//左右滑动事件
        {
            UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(backLayerPan:)];
            [cell.backLayer addGestureRecognizer:pan];
            [pan release];
        }
        
        __block typeof(self) weakSelf=self;
        
        if(_hasBackButton1)//背面按钮1
        {
            cell.backButton1=[KATButton buttonWithFrame:_backButton1Frame type:_backButton1Type color:_backButton1Color lineWidth:_backButtonLineWidth scale:_backButton1Scale andOnClickAction:nil];
            
            if(!_hasBackButtonClickAnimation)//无点击动画
            {
                cell.backButton1.onClickAnimation=nil;
            }
            
            [cell.backLayer addSubview:cell.backButton1];
            
            if(_hasBackButton1TapEvent)//点击事件
            {
                cell.backButton1.onClickAction=^
                {
                    [weakSelf backButton1Tap:cell.backButton1];
                };
            }
        }
        
        if(_hasBackButton2)//背面按钮2
        {
            cell.backButton2=[KATButton buttonWithFrame:_backButton2Frame type:_backButton2Type color:_backButton2Color lineWidth:_backButtonLineWidth scale:_backButton2Scale andOnClickAction:nil];
            
            if(!_hasBackButtonClickAnimation)//无点击动画
            {
                cell.backButton2.onClickAnimation=nil;
            }
            
            [cell.backLayer addSubview:cell.backButton2];
            
            if(_hasBackButton2TapEvent)//点击事件
            {
                cell.backButton2.onClickAction=^
                {
                    [weakSelf backButton2Tap:cell.backButton2];
                };
            }
        }
        
        if(_hasBackButton3)//背面按钮3
        {
            cell.backButton3=[KATButton buttonWithFrame:_backButton3Frame type:_backButton3Type color:_backButton3Color lineWidth:_backButtonLineWidth scale:_backButton3Scale andOnClickAction:nil];
            
            if(!_hasBackButtonClickAnimation)//无点击动画
            {
                cell.backButton3.onClickAnimation=nil;
            }
            
            [cell.backLayer addSubview:cell.backButton3];
            
            if(_hasBackButton3TapEvent)//点击事件
            {
                cell.backButton3.onClickAction=^
                {
                    [weakSelf backButton3Tap:cell.backButton3];
                };
            }
        }
        
        if(_hasBackButton4)//背面按钮4
        {
            cell.backButton4=[KATButton buttonWithFrame:_backButton4Frame type:_backButton4Type color:_backButton4Color lineWidth:_backButtonLineWidth scale:_backButton4Scale andOnClickAction:nil];
            
            if(!_hasBackButtonClickAnimation)//无点击动画
            {
                cell.backButton4.onClickAnimation=nil;
            }
            
            [cell.backLayer addSubview:cell.backButton4];
            
            if(_hasBackButton4TapEvent)//点击事件
            {
                cell.backButton4.onClickAction=^
                {
                    [weakSelf backButton4Tap:cell.backButton4];
                };
            }
        }
        
        if(_hasBackButton5)//背面按钮5
        {
            cell.backButton5=[KATButton buttonWithFrame:_backButton5Frame type:_backButton5Type color:_backButton5Color lineWidth:_backButtonLineWidth scale:_backButton5Scale andOnClickAction:nil];
            
            if(!_hasBackButtonClickAnimation)//无点击动画
            {
                cell.backButton5.onClickAnimation=nil;
            }
            
            [cell.backLayer addSubview:cell.backButton5];
            
            if(_hasBackButton5TapEvent)//点击事件
            {
                cell.backButton5.onClickAction=^
                {
                    [weakSelf backButton1Tap:cell.backButton5];
                };
            }
        }
        
        if(_hasBackButton6)//背面按钮6
        {
            cell.backButton6=[KATButton buttonWithFrame:_backButton6Frame type:_backButton6Type color:_backButton6Color lineWidth:_backButtonLineWidth scale:_backButton6Scale andOnClickAction:nil];
            
            if(!_hasBackButtonClickAnimation)//无点击动画
            {
                cell.backButton6.onClickAnimation=nil;
            }
            
            [cell.backLayer addSubview:cell.backButton6];
            
            if(_hasBackButton6TapEvent)//点击事件
            {
                cell.backButton6.onClickAction=^
                {
                    [weakSelf backButton6Tap:cell.backButton6];
                };
            }
        }
        
        if(_hasBackButton7)//背面按钮7
        {
            cell.backButton7=[KATButton buttonWithFrame:_backButton7Frame type:_backButton7Type color:_backButton7Color lineWidth:_backButtonLineWidth scale:_backButton7Scale andOnClickAction:nil];
            
            if(!_hasBackButtonClickAnimation)//无点击动画
            {
                cell.backButton7.onClickAnimation=nil;
            }
            
            [cell.backLayer addSubview:cell.backButton7];
            
            if(_hasBackButton7TapEvent)//点击事件
            {
                cell.backButton7.onClickAction=^
                {
                    [weakSelf backButton7Tap:cell.backButton7];
                };
            }
        }
        
        if(_hasBackLabel)//背景标签
        {
            cell.backLabel=[[[UILabel alloc] init] autorelease];
            cell.backLabel.frame=_backLabelFrame;
            cell.backLabel.textAlignment=_backLabelAlignment;
            cell.backLabel.font=_backLabelFont;
            cell.backLabel.textColor=_backLabelColor;
            cell.backLabel.backgroundColor=[UIColor clearColor];
            cell.backLabel.numberOfLines=_backLabelLines;
            cell.backLabel.lineBreakMode=_backLabelLineBreak;
            [cell.backLayer addSubview:cell.backLabel];
            
            if(_hasBackLabelTapEvent)//点击事件
            {
                cell.backLabel.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backLabelTap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.backLabel addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        
        //中间层
        cell.midLayer=[[[UIView alloc] init] autorelease];
        cell.midLayer.frame=CGRectMake(0, 0, cell.bounds.size.width, cell.bounds.size.height);
        cell.midLayer.backgroundColor=_midBgColor;
        [cell addSubview:cell.midLayer];
        
        if(_hasMidLayerTapEvent)//点击事件
        {
            singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(midLayerTap:)];
            singleTap.numberOfTapsRequired=1;//点击次数
            [cell.midLayer addGestureRecognizer:singleTap];//添加点击事件
            [singleTap release];
        }
        
        
        if(_canMoveLeft || _canMoveRight)//左右滑动事件
        {
            UISwipeGestureRecognizer *leftSwipe=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe:)];
            [leftSwipe setDirection:UISwipeGestureRecognizerDirectionLeft];
            [cell.midLayer addGestureRecognizer:leftSwipe];
            [leftSwipe release];
            
            UISwipeGestureRecognizer *rightSwipe=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipe:)];
            [rightSwipe setDirection:UISwipeGestureRecognizerDirectionRight];
            [cell.midLayer addGestureRecognizer:rightSwipe];
            [rightSwipe release];
            
            if(_movingTime>=0.0001)
            {
                cell.movingTime=_movingTime;
            }
            
            //拖动手势
            if(_canPanCell)
            {
                UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(cellPan:)];
                [cell.midLayer addGestureRecognizer:pan];
                pan.delegate=self;
                [pan release];
                
                _cellPanDisabled=NO;
            }
        }
        
        
        //表层(位于中间层之上)
        cell.faceLayer=[[[UIView alloc] init] autorelease];
        cell.faceLayer.frame=CGRectMake(0, 0, cell.midLayer.bounds.size.width, cell.midLayer.bounds.size.height);
        cell.faceLayer.backgroundColor=_faceBgColor;
        [cell.midLayer addSubview:cell.faceLayer];
        
        if(_hasFaceLayerTapEvent)//点击事件
        {
            singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(faceLayerTap:)];
            singleTap.numberOfTapsRequired=1;//点击次数
            [cell.faceLayer addGestureRecognizer:singleTap];//添加点击事件
            [singleTap release];
        }
        
        if(_hasLine1)//线1
        {
            cell.line1=[[[UIView alloc] init] autorelease];
            cell.line1.frame=_line1Frame;
            cell.line1.backgroundColor=_line1Color;
            [cell.faceLayer addSubview:cell.line1];
        }
        
        if(_hasLine2)//线2
        {
            cell.line2=[[[UIView alloc] init] autorelease];
            cell.line2.frame=_line2Frame;
            cell.line2.backgroundColor=_line2Color;
            [cell.faceLayer addSubview:cell.line2];
        }
        
        if(_hasSpButton)//特殊按钮
        {
            cell.spButton=[KATButton buttonWithFrame:CGRectZero];
            cell.spButton.color=KCOLOR_CLEAR;
            cell.spButton.type=KATButtonTypePoint;
            cell.spButton.lineWidth=1.0f;
            [cell.faceLayer addSubview:cell.spButton];
            
            if(_hasSpButtonTapEvent)//点击事件
            {
                cell.spButton.onClickAction=^
                {
                    [self spButtonTap:cell.spButton];
                };
            }
        }
        
        if(_hasImage)//图片
        {
            cell.image=[[[UIImageView alloc] init] autorelease];
            cell.image.frame=_imageFrame;
            cell.image.contentMode=UIViewContentModeScaleAspectFit;
            [cell.faceLayer addSubview:cell.image];
            
            if(_imageCorner>0)
            {
                cell.image.layer.cornerRadius=_imageCorner*_imageFrame.size.height;
                cell.image.layer.masksToBounds=YES;
            }
            else
            {
                cell.image.layer.cornerRadius=0;
                cell.image.layer.masksToBounds=NO;
            }
            
            if(_hasImageTapEvent)//点击事件
            {
                cell.image.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.image addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        
        if(_hasImage2)//图片2
        {
            cell.image2=[[[UIImageView alloc] init] autorelease];
            cell.image2.frame=_image2Frame;
            cell.image2.contentMode=UIViewContentModeScaleAspectFit;
            [cell.faceLayer addSubview:cell.image2];
            
            if(_image2Corner>0)
            {
                cell.image2.layer.cornerRadius=_image2Corner*_image2Frame.size.height;
                cell.image2.layer.masksToBounds=YES;
            }
            else
            {
                cell.image2.layer.cornerRadius=0;
                cell.image2.layer.masksToBounds=NO;
            }
            
            if(_hasImage2TapEvent)//点击事件
            {
                cell.image2.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(image2Tap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.image2 addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        
        if(_hasImage3)//图片3
        {
            cell.image3=[[[UIImageView alloc] init] autorelease];
            cell.image3.frame=_image3Frame;
            cell.image3.contentMode=UIViewContentModeScaleAspectFit;
            [cell.faceLayer addSubview:cell.image3];
            
            if(_image3Corner>0)
            {
                cell.image3.layer.cornerRadius=_image3Corner*_image3Frame.size.height;
                cell.image3.layer.masksToBounds=YES;
            }
            else
            {
                cell.image3.layer.cornerRadius=0;
                cell.image3.layer.masksToBounds=NO;
            }
            
            if(_hasImage3TapEvent)//点击事件
            {
                cell.image3.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(image3Tap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.image3 addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        
        if(_hasTitle)//标题
        {
            cell.title=[[[UILabel alloc] init] autorelease];
            cell.title.frame=_titleFrame;
            cell.title.textAlignment=_titleAlignment;
            cell.title.font=_titleFont;
            cell.title.textColor=_titleColor;
            cell.title.backgroundColor=[UIColor clearColor];
            cell.title.numberOfLines=_titleLines;
            cell.title.lineBreakMode=_titleLineBreak;
            [cell.faceLayer addSubview:cell.title];
            
            if(_hasTitleTapEvent)//点击事件
            {
                cell.title.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(titleTap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.title addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        if(_hasContent)//内容
        {
            cell.content=[[[UILabel alloc] init] autorelease];
            cell.content.frame=_contentFrame;
            cell.content.textAlignment=_contentAlignment;
            cell.content.font=_contentFont;
            cell.content.textColor=_contentColor;
            cell.content.backgroundColor=[UIColor clearColor];
            cell.content.numberOfLines=_contentLines;
            cell.content.lineBreakMode=_contentLineBreak;
            [cell.faceLayer addSubview:cell.content];
            
            if(_hasContentTapEvent)//点击事件
            {
                cell.content.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contentTap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.content addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        if(_hasRichTitle)//富文本标题
        {
            cell.richTitle=[KATLabel labelWithFrame:_richTitleFrame andStyle:_richTitleStyle];
            [cell.faceLayer addSubview:cell.richTitle];
            
            if(_hasRichTitleTapEvent)//点击事件
            {
                cell.richTitle.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(richTitleTap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.richTitle addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        if(_hasRichContent)//富文本内容
        {
            cell.richContent=[KATLabel labelWithFrame:_richContentFrame andStyle:_richContentStyle];
            [cell.faceLayer addSubview:cell.richContent];
            
            if(_hasRichContentTapEvent)//点击事件
            {
                cell.richContent.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(richContentTap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.richContent addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        if(_hasRichLabel)//富文本标签
        {
            cell.richLabel=[KATLabel labelWithFrame:_richLabelFrame andStyle:_richLabelStyle];
            [cell.faceLayer addSubview:cell.richLabel];
            
            if(_hasRichLabelTapEvent)//点击事件
            {
                cell.richLabel.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(richLabelTap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.richLabel addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        if(_hasText)//文本控件
        {
            cell.text=[[[UITextView alloc] init] autorelease];
            cell.text.frame=_textFrame;
            cell.text.textAlignment=_textAlignment;
            cell.text.font=_textFont;
            cell.text.textColor=_textColor;
            cell.text.backgroundColor=_textBgColor;
            cell.text.editable=_textCanEdit;
            cell.text.delegate=self;
            
            if(_hasTextBorder)//边界线
            {
                cell.text.layer.masksToBounds=YES;
                cell.text.layer.borderColor=_textBorderColor.CGColor;
                cell.text.layer.borderWidth=_textBorderWidth;
                cell.text.layer.cornerRadius=_textBorderCorner*_textFrame.size.height;
            }
            
            [cell.faceLayer addSubview:cell.text];
        }
        
        if(_hasBadge)//徽标
        {
            cell.badge=[[[UILabel alloc] init] autorelease];
            cell.badge.frame=_badgeFrame;
            cell.badge.textAlignment=_badgeAlignment;
            cell.badge.font=_badgeFont;
            cell.badge.textColor=_badgeTextColor;
            cell.badge.backgroundColor=_badgeBgColor;
            cell.badge.layer.cornerRadius=_badgeFrame.size.height*_badgeCorner;
            
            if(_badgeCorner>0)
            {
                cell.badge.layer.masksToBounds=YES;
            }
            
            cell.badge.numberOfLines=_badgeLines;
            cell.badge.lineBreakMode=_badgeLineBreak;
            
            if(_hasBadgeBorder)
            {
                cell.badge.layer.borderWidth=_badgeBorderWidth;
                cell.badge.layer.borderColor=_badgeBorderColor.CGColor;
            }
            
            [cell.faceLayer addSubview:cell.badge];
            
            if(_hasBadgeTapEvent)//点击事件
            {
                cell.badge.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(badgeTap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.badge addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        if(_hasLabel1)//标签1
        {
            cell.label1=[[[UILabel alloc] init] autorelease];
            cell.label1.frame=_label1Frame;
            cell.label1.textAlignment=_label1Alignment;
            cell.label1.font=_label1Font;
            cell.label1.textColor=_label1Color;
            cell.label1.backgroundColor=[UIColor clearColor];
            cell.label1.numberOfLines=_label1Lines;
            cell.label1.lineBreakMode=_label1LineBreak;
            [cell.faceLayer addSubview:cell.label1];
            
            if(_hasLabel1TapEvent)//点击事件
            {
                cell.label1.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(label1Tap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.label1 addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        if(_hasLabel2)//标签2
        {
            cell.label2=[[[UILabel alloc] init] autorelease];
            cell.label2.frame=_label2Frame;
            cell.label2.textAlignment=_label2Alignment;
            cell.label2.font=_label2Font;
            cell.label2.textColor=_label2Color;
            cell.label2.backgroundColor=[UIColor clearColor];
            cell.label2.numberOfLines=_label2Lines;
            cell.label2.lineBreakMode=_label2LineBreak;
            [cell.faceLayer addSubview:cell.label2];
            
            if(_hasLabel2TapEvent)//点击事件
            {
                cell.label2.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(label2Tap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.label2 addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        if(_hasLabel3)//标签3
        {
            cell.label3=[[[UILabel alloc] init] autorelease];
            cell.label3.frame=_label3Frame;
            cell.label3.textAlignment=_label3Alignment;
            cell.label3.font=_label3Font;
            cell.label3.textColor=_label3Color;
            cell.label3.backgroundColor=[UIColor clearColor];
            cell.label3.numberOfLines=_label3Lines;
            cell.label3.lineBreakMode=_label3LineBreak;
            [cell.faceLayer addSubview:cell.label3];
            
            if(_hasLabel3TapEvent)//点击事件
            {
                cell.label3.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(label3Tap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.label3 addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        if(_hasLabel4)//标签4
        {
            cell.label4=[[[UILabel alloc] init] autorelease];
            cell.label4.frame=_label4Frame;
            cell.label4.textAlignment=_label4Alignment;
            cell.label4.font=_label4Font;
            cell.label4.textColor=_label4Color;
            cell.label4.backgroundColor=[UIColor clearColor];
            cell.label4.numberOfLines=_label4Lines;
            cell.label4.lineBreakMode=_label4LineBreak;
            [cell.faceLayer addSubview:cell.label4];
            
            if(_hasLabel4TapEvent)//点击事件
            {
                cell.label4.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(label4Tap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.label4 addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        if(_hasLabel5)//标签5
        {
            cell.label5=[[[UILabel alloc] init] autorelease];
            cell.label5.frame=_label5Frame;
            cell.label5.textAlignment=_label5Alignment;
            cell.label5.font=_label5Font;
            cell.label5.textColor=_label5Color;
            cell.label5.backgroundColor=[UIColor clearColor];
            cell.label5.numberOfLines=_label5Lines;
            cell.label5.lineBreakMode=_label5LineBreak;
            [cell.faceLayer addSubview:cell.label5];
            
            if(_hasLabel5TapEvent)//点击事件
            {
                cell.label5.userInteractionEnabled=YES;
                singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(label5Tap:)];
                singleTap.numberOfTapsRequired=1;//点击次数
                [cell.label5 addGestureRecognizer:singleTap];//添加点击事件
                [singleTap release];
            }
        }
        
        if(_hasButton1)//按钮1
        {
            cell.button1=[KATButton buttonWithFrame:_button1Frame type:_button1Type color:_button1Color lineWidth:_buttonLineWidth scale:_button1Scale andOnClickAction:nil];
            
            if(!_hasButtonClickAnimation)//无点击动画
            {
                cell.button1.onClickAnimation=nil;
            }
            
            [cell.faceLayer addSubview:cell.button1];
            
            if(_hasButton1TapEvent)//点击事件
            {
                cell.button1.onClickAction=^
                {
                    [weakSelf button1Tap:cell.button1];
                };
            }
        }
        
        if(_hasButton2)//按钮2
        {
            cell.button2=[KATButton buttonWithFrame:_button2Frame type:_button2Type color:_button2Color lineWidth:_buttonLineWidth scale:_button2Scale andOnClickAction:nil];
            
            if(!_hasButtonClickAnimation)//无点击动画
            {
                cell.button2.onClickAnimation=nil;
            }
            
            [cell.faceLayer addSubview:cell.button2];
            
            if(_hasButton2TapEvent)//点击事件
            {
                cell.button2.onClickAction=^
                {
                    [weakSelf button2Tap:cell.button2];
                };
            }
        }
        
        if(_hasButton3)//按钮3
        {
            cell.button3=[KATButton buttonWithFrame:_button3Frame type:_button3Type color:_button3Color lineWidth:_buttonLineWidth scale:_button3Scale andOnClickAction:nil];
            
            if(!_hasButtonClickAnimation)//无点击动画
            {
                cell.button3.onClickAnimation=nil;
            }
            
            [cell.faceLayer addSubview:cell.button3];
            
            if(_hasButton3TapEvent)//点击事件
            {
                cell.button3.onClickAction=^
                {
                    [weakSelf button3Tap:cell.button3];
                };
            }
        }
        
        
        //上分隔线（底层）
        if(_hasTopLine && _topLineColor)
        {
            UIView *topLine=[[[UIView alloc] init] autorelease];
            topLine.frame=_topLineFrame;
            topLine.backgroundColor=_topLineColor;
            topLine.userInteractionEnabled=NO;
            [cell addSubview:topLine];
        }
        
        //下分隔线（底层）
        if(_hasBottomLine && _bottomLineColor)
        {
            UIView *bottomLine=[[[UIView alloc] init] autorelease];
            bottomLine.frame=_bottomLineFrame;
            bottomLine.backgroundColor=_bottomLineColor;
            bottomLine.userInteractionEnabled=NO;
            [cell addSubview:bottomLine];
        }
        
        [_cellArray put:cell];
        
    }
    
    
    //是否点击恢复cell位置
    if(_isTapTableToRestoreCells)
    {
        UITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tableTap)];
        singleTap.numberOfTapsRequired=1;//点击次数
        [self addGestureRecognizer:singleTap];//添加点击事件
        [singleTap release];
    }
    
    
    //初始化上推控件
    if(_hasPushFooter)
    {
        self.pushFooter=[KATStandardTableFooter tableFooterWithHeight:_pullHeaderHeight andScrollView:_scrollView];
        _pushFooter.eventDelegate=self;
        
        [_pushFooter initFooter];
    }
    
    _state=TABLE_STATE_READY;
}



//在表头重新加载数据
- (void)reloadData:(KATArray<__kindof KATTableCellData *> *)dataArray withMessage:(NSString *)message andSucceed:(BOOL)succeed
{
    _isScrollDisabled=NO;
    
    if(_state!=TABLE_STATE_RELOAD)//状态判断
    {
        if(dataArray && dataArray.length>0)//非空数据
        {
            //状态重置
            _state=TABLE_STATE_RELOAD;
            self.scrollView.scrollEnabled=NO;//禁止滚动
            _pages=0;
            
            if(_remoteImageUpdateTimer)//取消定时器
            {
                [_remoteImageUpdateTimer invalidate];
                self.remoteImageUpdateTimer=nil;
            }
            
            _isRemoteImageUpdateTimerWorking=NO;
            
            _cellOffset=0;
            _displayOffset=0;
            _cellsRemoved=0;
            
            
            //先清空列表原来的内容
            for(UIView *item in self.scrollView.subviews)
            {
                if(item.frame.origin.y+0.1>=_startPositionY)
                {
                    [item removeFromSuperview];
                }
            }
            
            
            self.dataArray=dataArray;//数据数组
            
            
            if(_hasNoneDataTips && _noneDataTipsLabel)//清除内容提示
            {
                [_noneDataTipsLabel removeFromSuperview];
            }
            
            //加载下拉控件
            if(_hasPullHeader && _pullHeader)
            {
                [self.scrollView addSubview:_pullHeader];
            }
            
        
            //加载控件数组
            for(int i=0;i<_cellsDisplayMax && i<_dataArray.length;i++)
            {
                KATTableCellData *data=(KATTableCellData *)[_dataArray get:i];
                KATTableCell *cell=(KATTableCell *)[_cellArray get:i];
                
                data.state=TABLE_CELL_STATE_READY;
                cell.state=TABLE_CELL_STATE_READY;
                
                cell.data=data;
                cell.alpha=1.0f;
                
                cell.backLayer.tag=cell.num;
                cell.midLayer.tag=cell.num;
                cell.faceLayer.tag=cell.num;
                
                if(_hasBackButton1)
                {
                    cell.backButton1.tag=cell.num;
                }
                
                if(_hasBackButton2)
                {
                    cell.backButton2.tag=cell.num;
                }
                
                if(_hasBackButton3)
                {
                    cell.backButton3.tag=cell.num;
                }
                
                if(_hasBackButton4)
                {
                    cell.backButton4.tag=cell.num;
                }
                
                if(_hasBackButton5)
                {
                    cell.backButton5.tag=cell.num;
                }
                
                if(_hasBackButton6)
                {
                    cell.backButton6.tag=cell.num;
                }
                
                if(_hasBackButton7)
                {
                    cell.backButton7.tag=cell.num;
                }
                
                if(_hasButton1)
                {
                    cell.button1.tag=cell.num;
                }
                
                if(_hasButton2)
                {
                    cell.button2.tag=cell.num;
                }
                
                if(_hasButton3)
                {
                    cell.button3.tag=cell.num;
                }
                
                
                if(_hasBackBgColor)//有背面层背景色
                {
                    if(data.hasBackBgColor && data.backBgColor)
                    {
                        cell.backLayer.backgroundColor=data.backBgColor;
                    }
                    else
                    {
                        cell.backLayer.backgroundColor=_backBgColor;
                    }
                }
                
                
                if(_hasMidBgColor)//有中间层背景色
                {
                    if(data.hasMidBgColor && data.midBgColor)
                    {
                        cell.midLayer.backgroundColor=data.midBgColor;
                    }
                    else
                    {
                        cell.midLayer.backgroundColor=_midBgColor;
                    }
                }
                
                
                if(_hasFaceBgColor)//有表层背景色
                {
                    if(data.hasFaceBgColor && data.faceBgColor)
                    {
                        cell.faceLayer.backgroundColor=data.faceBgColor;
                    }
                    else
                    {
                        cell.faceLayer.backgroundColor=_faceBgColor;
                    }
                }
                
                
                if(_hasImage)//图片
                {
                    if(data.hasImage)
                    {
                        cell.image.hidden=NO;
                        
                        cell.image.tag=cell.num;
                        
                        if(data.hasImageFrame)
                        {
                            cell.image.frame=data.imageFrame;
                        }
                        else
                        {
                            cell.image.frame=_imageFrame;
                        }
                        
                        
                        if(data.isImageReady && !data.isLoadImageFail)
                        {
                            if(data.hasImageMemory && data.image)
                            {
                                cell.image.image=data.image;
                            }
                            else if(data.imagePath)
                            {
                                cell.image.image=[UIImage imageWithContentsOfFile:data.imagePath];
                            }
                        }
                        else
                        {
                            if(_hasCacheImage && _cacheImage)
                            {
                                cell.image.image=_cacheImage;
                            }
                            else
                            {
                                cell.image.image=nil;
                            }
                            
                        }
                    }
                    else
                    {
                        cell.image.hidden=YES;
                    }
                }
                
                
                if(_hasImage2)//图片2
                {
                    if(data.hasImage2)
                    {
                        cell.image2.hidden=NO;
                        
                        cell.image2.tag=cell.num;
                        
                        
                        if(data.hasImage2Frame)
                        {
                            cell.image2.frame=data.image2Frame;
                        }
                        else
                        {
                            cell.image2.frame=_image2Frame;
                        }
                        
                        if(data.isImage2Ready && !data.isLoadImage2Fail)
                        {
                            if(data.hasImage2Memory && data.image2)
                            {
                                cell.image2.image=data.image2;
                            }
                            else if(data.image2Path)
                            {
                                cell.image2.image=[UIImage imageWithContentsOfFile:data.image2Path];
                            }
                        }
                        else
                        {
                            if(_hasCacheImage && _cacheImage)
                            {
                                cell.image2.image=_cacheImage;
                            }
                            else
                            {
                                cell.image2.image=nil;
                            }
                        }
                    }
                    else
                    {
                        cell.image2.hidden=YES;
                    }
                }
                
                
                if(_hasImage3)//图片3
                {
                    if(data.hasImage3)
                    {
                        cell.image3.hidden=NO;
                        
                        cell.image3.tag=cell.num;
                        
                        
                        if(data.hasImage3Frame)
                        {
                            cell.image3.frame=data.image3Frame;
                        }
                        else
                        {
                            cell.image3.frame=_image3Frame;
                        }
                        
                        
                        if(data.isImage3Ready && !data.isLoadImage3Fail)
                        {
                            if(data.hasImage3Memory && data.image3)
                            {
                                cell.image3.image=data.image3;
                            }
                            else if(data.image3Path)
                            {
                                cell.image3.image=[UIImage imageWithContentsOfFile:data.image3Path];
                            }
                        }
                        else
                        {
                            if(_hasCacheImage && _cacheImage)
                            {
                                cell.image3.image=_cacheImage;
                            }
                            else
                            {
                                cell.image3.image=nil;
                            }
                        }
                    }
                    else
                    {
                        cell.image3.hidden=YES;
                    }
                }
                
                
                if(_hasTitle && data.title)//标题
                {
                    cell.title.hidden=NO;
                    
                    cell.title.tag=cell.num;
                    cell.title.text=data.title;
                    
                    if(data.hasTitleColor && data.titleColor)
                    {
                        cell.title.textColor=data.titleColor;
                    }
                    else
                    {
                        cell.title.textColor=_titleColor;
                    }
                    
                    if(data.hasTitleFont && data.titleFont)
                    {
                        cell.title.font=data.titleFont;
                    }
                    else
                    {
                        cell.title.font=_titleFont;
                    }
                    
                    if(data.hasTitleFrame)
                    {
                        cell.title.frame=data.titleFrame;
                    }
                    else
                    {
                        cell.title.frame=_titleFrame;
                    }
                }
                else
                {
                    cell.title.hidden=YES;
                }
                
                
                if(_hasContent && data.content)//内容
                {
                    cell.content.hidden=NO;
                    
                    cell.content.tag=cell.num;
                    cell.content.text=data.content;
                    
                    if(data.hasContentColor && data.contentColor)
                    {
                        cell.content.textColor=data.contentColor;
                    }
                    else
                    {
                        cell.content.textColor=_contentColor;
                    }
                    
                    if(data.hasContentFont && data.contentFont)
                    {
                        cell.content.font=data.contentFont;
                    }
                    else
                    {
                        cell.content.font=_contentFont;
                    }
                    
                    if(data.hasContentFrame)
                    {
                        cell.content.frame=data.contentFrame;
                    }
                    else
                    {
                        cell.content.frame=_contentFrame;
                    }
                }
                else
                {
                    cell.content.hidden=YES;
                }
                
                
                if(_hasRichTitle && data.richTitle)//富文本标题
                {
                    cell.richTitle.hidden=NO;
                    
                    cell.richTitle.tag=cell.num;
                    cell.richTitle.text=data.richTitle;
                    
                    if(data.hasRichTitleStyle && data.richTitleStyle)
                    {
                        cell.richTitle.style=data.richTitleStyle;
                    }
                    else
                    {
                        cell.richTitle.style=_richTitleStyle;
                    }
                    
                    if(data.hasRichTitleFrame)
                    {
                        cell.richTitle.frame=data.richTitleFrame;
                    }
                    else
                    {
                        cell.richTitle.frame=_richTitleFrame;
                    }
                }
                else
                {
                    cell.richTitle.hidden=YES;
                }
                
                
                if(_hasRichContent && data.richContent)//富文本内容
                {
                    cell.richContent.hidden=NO;
                    
                    cell.richContent.tag=cell.num;
                    cell.richContent.text=data.richContent;
                    
                    if(data.hasRichContentStyle && data.richContentStyle)
                    {
                        cell.richContent.style=data.richContentStyle;
                    }
                    else
                    {
                        cell.richContent.style=_richContentStyle;
                    }
                    
                    if(data.hasRichContentFrame)
                    {
                        cell.richContent.frame=data.richContentFrame;
                    }
                    else
                    {
                        cell.richContent.frame=_richContentFrame;
                    }
                }
                else
                {
                    cell.richContent.hidden=YES;
                }
                
                
                if(_hasRichLabel && data.richLabel)//富文本标签
                {
                    cell.richLabel.hidden=NO;
                    
                    cell.richLabel.tag=cell.num;
                    cell.richLabel.text=data.richLabel;
                }
                else
                {
                    cell.richLabel.hidden=YES;
                }
                
                
                if(_hasText && data.text)//文本
                {
                    cell.text.hidden=NO;
                    
                    cell.text.tag=cell.num;
                    cell.text.text=data.text;
                    
                    if(data.hasTextColor && data.textColor)
                    {
                        cell.text.textColor=data.textColor;
                    }
                    else
                    {
                        cell.text.textColor=_textColor;
                    }
                    
                    if(data.hasTextBgColor && data.textBgColor)
                    {
                        cell.text.backgroundColor=data.textBgColor;
                    }
                    else
                    {
                        cell.text.backgroundColor=_textBgColor;
                    }
                    
                    if(data.hasTextFont && data.textFont)
                    {
                        cell.text.font=data.textFont;
                    }
                    else
                    {
                        cell.text.font=_textFont;
                    }
                    
                    if(data.hasTextFrame)
                    {
                        cell.text.frame=data.textFrame;
                    }
                    else
                    {
                        cell.text.frame=_textFrame;
                    }
                }
                else
                {
                    cell.text.hidden=YES;
                }
                
                
                if(_hasBadge)//徽标
                {
                    cell.badge.tag=cell.num;
                    
                    if(data.hasBadge && data.badge)
                    {
                        cell.badge.text=data.badge;
                        cell.badge.hidden=NO;
                        
                        if(data.hasBadgeBgColor && data.badgeBgColor)
                        {
                            cell.badge.backgroundColor=data.badgeBgColor;
                        }
                        else
                        {
                            cell.badge.backgroundColor=_badgeBgColor;//默认颜色
                        }
                        
                        if(data.hasBadgeTextColor && data.badgeTextColor)
                        {
                            cell.badge.textColor=data.badgeTextColor;
                        }
                        else
                        {
                            cell.badge.textColor=_badgeTextColor;//默认颜色
                            
                        }
                        
                        
                        if(_hasBadgeBorder)//边界颜色
                        {
                            cell.badge.layer.borderColor=_badgeBorderColor.CGColor;
                            
                            if(data.hasBadgeBorderColor && data.badgeBorderColor)
                            {
                                cell.badge.layer.borderColor=data.badgeBorderColor.CGColor;
                            }
                        }
                        
                        
                        if(data.hasBadgeFrame)
                        {
                            cell.badge.frame=data.badgeFrame;
                        }
                        else
                        {
                            cell.badge.frame=_badgeFrame;
                        }
                        
                    }
                    else
                    {
                        cell.badge.hidden=YES;
                    }
                }
                
                
                if(_hasSpButton)//特殊按钮
                {
                    cell.spButton.tag=cell.num;
                    
                    if(data.hasSpButton && data.spButtonColor)
                    {
                        cell.spButton.hidden=NO;

                        cell.spButton.type=data.spButtonType;
                        cell.spButton.color=data.spButtonColor;
                        cell.spButton.lineWidth=data.spButtonLineWidth;
                        cell.spButton.scale=data.spButtonScale;
                        
                        cell.spButton.frame=data.spButtonFrame;
                    }
                    else
                    {
                        cell.spButton.hidden=YES;
                    }
                }
                
                
                if(_hasLabel1 && data.label1)//标签1
                {
                    cell.label1.hidden=NO;
                    
                    cell.label1.tag=cell.num;
                    cell.label1.text=data.label1;
                    
                    if(data.hasLabel1Color && data.label1Color)
                    {
                        cell.label1.textColor=data.label1Color;
                    }
                    else
                    {
                        cell.label1.textColor=_label1Color;
                    }
                }
                else
                {
                    cell.label1.hidden=YES;
                }
                
                
                if(_hasLabel2 && data.label2)//标签2
                {
                    cell.label2.hidden=NO;
                    
                    cell.label2.tag=cell.num;
                    cell.label2.text=data.label2;
                    
                    if(data.hasLabel2Color && data.label2Color)
                    {
                        cell.label2.textColor=data.label2Color;
                    }
                    else
                    {
                        cell.label2.textColor=_label2Color;
                    }
                }
                else
                {
                    cell.label2.hidden=YES;
                }
                
                
                if(_hasLabel3 && data.label3)//标签3
                {
                    cell.label3.hidden=NO;
                    
                    cell.label3.tag=cell.num;
                    cell.label3.text=data.label3;
                    
                    if(data.hasLabel3Color && data.label3Color)
                    {
                        cell.label3.textColor=data.label3Color;
                    }
                    else
                    {
                        cell.label3.textColor=_label3Color;
                    }
                }
                else
                {
                    cell.label3.hidden=YES;
                }
                
                
                if(_hasLabel4 && data.label4)//标签4
                {
                    cell.label4.hidden=NO;
                    
                    cell.label4.tag=cell.num;
                    cell.label4.text=data.label4;
                    
                    if(data.hasLabel4Color && data.label4Color)
                    {
                        cell.label4.textColor=data.label4Color;
                    }
                    else
                    {
                        cell.label4.textColor=_label4Color;
                    }
                }
                else
                {
                    cell.label4.hidden=YES;
                }
                
                
                if(_hasLabel5 && data.label5)//标签5
                {
                    cell.label5.hidden=NO;
                    
                    cell.label5.tag=cell.num;
                    cell.label5.text=data.label5;
                    
                    if(data.hasLabel5Color && data.label5Color)
                    {
                        cell.label5.textColor=data.label5Color;
                    }
                    else
                    {
                        cell.label5.textColor=_label5Color;
                    }
                }
                else
                {
                    cell.label5.hidden=YES;
                }
                
                
                if(_hasBackLabel && data.backLabel)//背部标签
                {
                    cell.backLabel.hidden=NO;
                    
                    cell.backLabel.tag=cell.num;
                    cell.backLabel.text=data.backLabel;
                    
                    if(data.hasBackLabelColor && data.backLabelColor)
                    {
                        cell.backLabel.textColor=data.backLabelColor;
                    }
                    else
                    {
                        cell.backLabel.textColor=_backLabelColor;
                    }
                    
                    if(data.hasBackLabelFont && data.backLabelFont)
                    {
                        cell.backLabel.font=data.backLabelFont;
                    }
                    else
                    {
                        cell.backLabel.font=data.backLabelFont;
                    }
                    
                    if(data.hasBackLabelFrame)
                    {
                        cell.backLabel.frame=_backLabelFrame;
                    }
                }
                else
                {
                    cell.backLabel.hidden=YES;
                }
                
                
                //左右移动归位
                if(_canMoveLeft || _canMoveRight)
                {
                    if(cell.state!=TABLE_CELL_STATE_READY)
                    {
                        [cell backToPositionWithAnimated:NO];
                    }
                }
                
                
                //添加到列表视图
                cell.frame=CGRectMake(0, _startPositionY+_cellMarginTop+i*(_cellHeight+_cellMarginInner), _cellWidth, _cellHeight);
                
                [self.scrollView addSubview:cell];
            }
            
            //设置最后的cell内容y坐标
            _endPositionY=_startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom;
            
            
            //设置滚动视图内容大小
            if(_startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom+_bottomInsertHeight > self.scrollView.bounds.size.height)
            {
                self.scrollView.contentSize=CGSizeMake(self.scrollView.bounds.size.width, _startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom+_bottomInsertHeight);
            }
            else
            {
                self.scrollView.contentSize=CGSizeMake(self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
            }
            
            
            //加载上推控件
            if(_hasPushFooter && _pushFooter)
            {
                _pushFooter.frame=CGRectMake(0, self.scrollView.contentSize.height, _cellWidth, _pushFooterHeight);
                [self.scrollView addSubview:_pushFooter];
            }
            
            self.scrollView.scrollEnabled=YES;//解禁滚动
            
            _reloadTimes++;
            
            
            //开启远程图片刷新
            [self startRemoteImageUpdating];
        }
        else//空内容
        {
            //生成空数组
            self.dataArray=[KATArray array];
            
            _pages=0;
            
            //先清空列表原来的内容
            for(UIView *item in self.scrollView.subviews)
            {
                if(item.frame.origin.y+0.1>=_startPositionY)
                {
                    [item removeFromSuperview];
                }
            }
            
            //加载下拉控件
            if(_hasPullHeader && _pullHeader)
            {
                [self.scrollView addSubview:_pullHeader];
            }
            
            self.scrollView.contentSize=CGSizeMake(self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
            
            //添加空内容提示
            if(_hasNoneDataTips && _noneDataTipsLabel)
            {
                [_scrollView addSubview:_noneDataTipsLabel];
            }
        }
        
        if(_eventDelegate && [_eventDelegate respondsToSelector:@selector(tableViewDidLoad:)])
        {
            [_eventDelegate tableViewDidLoad:self];
        }
    }
    
    //更新序号
    [self updateCellDataNum];
    
    _state=TABLE_STATE_READY;//状态改变
    
    //更新下拉头
    if(_hasPullHeader && _pullHeader)
    {
        if(succeed)
        {
            [_pullHeader successWithMessage:message];
        }
        else
        {
            [_pullHeader failWithMessage:message];
        }
    }
    
    
    [self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];//回到原点
    
    //更新上推底
    if(_hasPushFooter && _pushFooter)
    {
        [_pushFooter updatePosition];
        
        if(_reloadTimes>0)
        {
            [_pushFooter enableFooter];
        }
        else
        {
            [_pushFooter disableFooter];
        }
    }
    
    //解锁
    _pullHeader.locked=NO;
    _pushFooter.locked=NO;
}



//添加内容
- (void)moreData:(KATArray<__kindof KATTableCellData *> *)dataArray withMessage:(NSString *)message
{
    BOOL loaded=NO;
    
    if(_state!=TABLE_STATE_MORE)
    {
        if(dataArray && dataArray.length>0)//非空数据
        {
            _state=TABLE_STATE_MORE;
            _pages++;
            
            if(_dataArray.length<_cellsDisplayMax)//没使用完所有的显示cell，则继续加入显示cell
            {
                for(int i=0;i+_dataArray.length<_cellsDisplayMax && i<dataArray.length;i++)
                {
                    KATTableCellData *data=(KATTableCellData *)[dataArray get:i];
                    KATTableCell *cell=(KATTableCell *)[_cellArray get:_dataArray.length+i];
                    
                    cell.data=data;
                    cell.alpha=1.0f;
                    
                    cell.backLayer.tag=cell.num;
                    cell.midLayer.tag=cell.num;
                    cell.faceLayer.tag=cell.num;
                    
                    if(_hasBackButton1)
                    {
                        cell.backButton1.tag=cell.num;
                    }
                    
                    if(_hasBackButton2)
                    {
                        cell.backButton2.tag=cell.num;
                    }
                    
                    if(_hasBackButton3)
                    {
                        cell.backButton3.tag=cell.num;
                    }
                    
                    if(_hasBackButton4)
                    {
                        cell.backButton4.tag=cell.num;
                    }
                    
                    if(_hasBackButton5)
                    {
                        cell.backButton5.tag=cell.num;
                    }
                    
                    if(_hasBackButton6)
                    {
                        cell.backButton6.tag=cell.num;
                    }
                    
                    if(_hasBackButton7)
                    {
                        cell.backButton7.tag=cell.num;
                    }
                    
                    if(_hasButton1)
                    {
                        cell.button1.tag=cell.num;
                    }
                    
                    if(_hasButton2)
                    {
                        cell.button2.tag=cell.num;
                    }
                    
                    if(_hasButton3)
                    {
                        cell.button3.tag=cell.num;
                    }
                    
                    
                    if(_hasBackBgColor)//有背面层背景色
                    {
                        if(data.hasBackBgColor && data.backBgColor)
                        {
                            cell.backLayer.backgroundColor=data.backBgColor;
                        }
                        else
                        {
                            cell.backLayer.backgroundColor=_backBgColor;
                        }
                    }
                    
                    
                    if(_hasMidBgColor)//有中间层背景色
                    {
                        if(data.hasMidBgColor && data.midBgColor)
                        {
                            cell.midLayer.backgroundColor=data.midBgColor;
                        }
                        else
                        {
                            cell.midLayer.backgroundColor=_midBgColor;
                        }
                    }
                    
                    
                    if(_hasFaceBgColor)//有表层背景色
                    {
                        if(data.hasFaceBgColor && data.faceBgColor)
                        {
                            cell.faceLayer.backgroundColor=data.faceBgColor;
                        }
                        else
                        {
                            cell.faceLayer.backgroundColor=_faceBgColor;
                        }
                    }
                    
                    
                    if(_hasImage)//图片
                    {
                        if(data.hasImage)
                        {
                            cell.image.hidden=NO;
                            
                            cell.image.tag=cell.num;
                            
                            
                            if(data.hasImageFrame)
                            {
                                cell.image.frame=data.imageFrame;
                            }
                            else
                            {
                                cell.image.frame=_imageFrame;
                            }
                            
                            
                            if(data.isImageReady && !data.isLoadImageFail)
                            {
                                if(data.hasImageMemory && data.image)
                                {
                                    cell.image.image=data.image;
                                }
                                else if(data.imagePath)
                                {
                                    cell.image.image=[UIImage imageWithContentsOfFile:data.imagePath];
                                }
                            }
                            else
                            {
                                if(_hasCacheImage && _cacheImage)
                                {
                                    cell.image.image=_cacheImage;
                                }
                                else
                                {
                                    cell.image.image=nil;
                                }
                            }
                        }
                        else
                        {
                            cell.image.hidden=YES;
                        }
                    }
                    
                    
                    if(_hasImage2)//图片2
                    {
                        if(data.hasImage2)
                        {
                            cell.image2.hidden=NO;
                            
                            cell.image2.tag=cell.num;
                            
                            
                            if(data.hasImage2Frame)
                            {
                                cell.image2.frame=data.image2Frame;
                            }
                            else
                            {
                                cell.image2.frame=_image2Frame;
                            }
                            
                            if(data.isImage2Ready && !data.isLoadImage2Fail)
                            {
                                if(data.hasImage2Memory && data.image2)
                                {
                                    cell.image2.image=data.image2;
                                }
                                else if(data.image2Path)
                                {
                                    cell.image2.image=[UIImage imageWithContentsOfFile:data.image2Path];
                                }
                            }
                            else
                            {
                                if(_hasCacheImage && _cacheImage)
                                {
                                    cell.image2.image=_cacheImage;
                                }
                                else
                                {
                                    cell.image2.image=nil;
                                }
                            }
                        }
                        else
                        {
                            cell.image2.hidden=YES;
                        }
                    }
                    
                    
                    if(_hasImage3)//图片3
                    {
                        if(data.hasImage3)
                        {
                            cell.image3.hidden=NO;
                            
                            cell.image3.tag=cell.num;
                            
                            
                            if(data.hasImage3Frame)
                            {
                                cell.image3.frame=data.image3Frame;
                            }
                            else
                            {
                                cell.image3.frame=_image3Frame;
                            }
                            
                            
                            if(data.isImage3Ready && !data.isLoadImage3Fail)
                            {
                                if(data.hasImage3Memory && data.image3)
                                {
                                    cell.image3.image=data.image3;
                                }
                                else if(data.image3Path)
                                {
                                    cell.image3.image=[UIImage imageWithContentsOfFile:data.image3Path];
                                }
                            }
                            else
                            {
                                if(_hasCacheImage && _cacheImage)
                                {
                                    cell.image3.image=_cacheImage;
                                }
                                else
                                {
                                    cell.image3.image=nil;
                                }
                            }
                        }
                        else
                        {
                            cell.image3.hidden=YES;
                        }
                    }
                    
                    
                    if(_hasTitle && data.title)//标题
                    {
                        cell.title.hidden=NO;
                        
                        cell.title.tag=cell.num;
                        cell.title.text=data.title;
                        
                        if(data.hasTitleColor && data.titleColor)
                        {
                            cell.title.textColor=data.titleColor;
                        }
                        else
                        {
                            cell.title.textColor=_titleColor;
                        }
                        
                        if(data.hasTitleFont && data.titleFont)
                        {
                            cell.title.font=data.titleFont;
                        }
                        else
                        {
                            cell.title.font=_titleFont;
                        }
                        
                        if(data.hasTitleFrame)
                        {
                            cell.title.frame=data.titleFrame;
                        }
                        else
                        {
                            cell.title.frame=_titleFrame;
                        }
                    }
                    else
                    {
                        cell.title.hidden=YES;
                    }
                    
                    
                    if(_hasContent && data.content)//内容
                    {
                        cell.content.hidden=NO;
                        
                        cell.content.tag=cell.num;
                        cell.content.text=data.content;
                        
                        if(data.hasContentColor && data.contentColor)
                        {
                            cell.content.textColor=data.contentColor;
                        }
                        else
                        {
                            cell.content.textColor=_contentColor;
                        }
                        
                        if(data.hasContentFont && data.contentFont)
                        {
                            cell.content.font=data.contentFont;
                        }
                        else
                        {
                            cell.content.font=_contentFont;
                        }
                        
                        if(data.hasContentFrame)
                        {
                            cell.content.frame=data.contentFrame;
                        }
                        else
                        {
                            cell.content.frame=_contentFrame;
                        }
                    }
                    else
                    {
                        cell.content.hidden=YES;
                    }
                    
                    
                    if(_hasRichTitle && data.richTitle)//富文本标题
                    {
                        cell.richTitle.hidden=NO;
                        
                        cell.richTitle.tag=cell.num;
                        cell.richTitle.text=data.richTitle;
                        
                        if(data.hasRichTitleStyle && data.richTitleStyle)
                        {
                            cell.richTitle.style=data.richTitleStyle;
                        }
                        else
                        {
                            cell.richTitle.style=_richTitleStyle;
                        }
                        
                        if(data.hasRichTitleFrame)
                        {
                            cell.richTitle.frame=data.richTitleFrame;
                        }
                        else
                        {
                            cell.richTitle.frame=_richTitleFrame;
                        }
                    }
                    else
                    {
                        cell.richTitle.hidden=YES;
                    }
                    
                    
                    if(_hasRichContent && data.richContent)//富文本内容
                    {
                        cell.richContent.hidden=NO;
                        
                        cell.richContent.tag=cell.num;
                        cell.richContent.text=data.richContent;
                        
                        if(data.hasRichContentStyle && data.richContentStyle)
                        {
                            cell.richContent.style=data.richContentStyle;
                        }
                        else
                        {
                            cell.richContent.style=_richContentStyle;
                        }
                        
                        if(data.hasRichContentFrame)
                        {
                            cell.richContent.frame=data.richContentFrame;
                        }
                        else
                        {
                            cell.richContent.frame=_richContentFrame;
                        }
                    }
                    else
                    {
                        cell.richContent.hidden=YES;
                    }
                    
                    
                    if(_hasRichLabel && data.richLabel)//富文本标签
                    {
                        cell.richLabel.hidden=NO;
                        
                        cell.richLabel.tag=cell.num;
                        cell.richLabel.text=data.richLabel;
                    }
                    else
                    {
                        cell.richLabel.hidden=YES;
                    }
                    
                    
                    if(_hasText && data.text)//文本
                    {
                        cell.text.hidden=NO;
                        
                        cell.text.tag=cell.num;
                        cell.text.text=data.text;
                        
                        if(data.hasTextColor && data.textColor)
                        {
                            cell.text.textColor=data.textColor;
                        }
                        else
                        {
                            cell.text.textColor=_textColor;
                        }
                        
                        if(data.hasTextBgColor && data.textBgColor)
                        {
                            cell.text.backgroundColor=data.textBgColor;
                        }
                        else
                        {
                            cell.text.backgroundColor=_textBgColor;
                        }
                        
                        if(data.hasTextFont && data.textFont)
                        {
                            cell.text.font=data.textFont;
                        }
                        else
                        {
                            cell.text.font=_textFont;
                        }
                        
                        if(data.hasTextFrame)
                        {
                            cell.text.frame=data.textFrame;
                        }
                        else
                        {
                            cell.text.frame=_textFrame;
                        }
                    }
                    else
                    {
                        cell.text.hidden=YES;
                    }
                    
                    if(_hasBadge)//徽标
                    {
                        cell.badge.tag=cell.num;
                        
                        if(data.hasBadge && data.badge)
                        {
                            cell.badge.text=data.badge;
                            cell.badge.hidden=NO;
                            
                            if(data.hasBadgeBgColor && data.badgeBgColor)
                            {
                                cell.badge.backgroundColor=data.badgeBgColor;
                            }
                            else
                            {
                                cell.badge.backgroundColor=_badgeBgColor;//默认颜色
                            }
                            
                            if(data.hasBadgeTextColor && data.badgeTextColor)
                            {
                                cell.badge.textColor=data.badgeTextColor;
                            }
                            else
                            {
                                cell.badge.textColor=_badgeTextColor;//默认颜色
                            }
                            
                            if(_hasBadgeBorder)//边界颜色
                            {
                                cell.badge.layer.borderColor=_badgeBorderColor.CGColor;
                                
                                if(data.hasBadgeBorderColor && data.badgeBorderColor)
                                {
                                    cell.badge.layer.borderColor=data.badgeBorderColor.CGColor;
                                }
                            }
                            
                            if(data.hasBadgeFrame)
                            {
                                cell.badge.frame=data.badgeFrame;
                            }
                            else
                            {
                                cell.badge.frame=_badgeFrame;
                            }
                        }
                        else
                        {
                            cell.badge.hidden=YES;
                        }
                    }
                    
                    
                    if(_hasSpButton)//特殊按钮
                    {
                        cell.spButton.tag=cell.num;
                        
                        if(data.hasSpButton && data.spButtonColor)
                        {
                            cell.spButton.hidden=NO;

                            cell.spButton.type=data.spButtonType;
                            cell.spButton.color=data.spButtonColor;
                            cell.spButton.lineWidth=data.spButtonLineWidth;
                            cell.spButton.scale=data.spButtonScale;
                            
                            cell.spButton.frame=data.spButtonFrame;
                        }
                        else
                        {
                            cell.spButton.hidden=YES;
                        }
                    }
                    
                    
                    if(_hasLabel1 && data.label1)//标签1
                    {
                        cell.label1.hidden=NO;
                        
                        cell.label1.tag=cell.num;
                        cell.label1.text=data.label1;
                        
                        if(data.hasLabel1Color && data.label1Color)
                        {
                            cell.label1.textColor=data.label1Color;
                        }
                        else
                        {
                            cell.label1.textColor=_label1Color;
                        }
                    }
                    else
                    {
                        cell.label1.hidden=YES;
                    }
                    
                    
                    if(_hasLabel2 && data.label2)//标签2
                    {
                        cell.label2.hidden=NO;
                        
                        cell.label2.tag=cell.num;
                        cell.label2.text=data.label2;
                        
                        if(data.hasLabel2Color && data.label2Color)
                        {
                            cell.label2.textColor=data.label2Color;
                        }
                        else
                        {
                            cell.label2.textColor=_label2Color;
                        }
                    }
                    else
                    {
                        cell.label2.hidden=YES;
                    }
                    
                    
                    if(_hasLabel3 && data.label3)//标签3
                    {
                        cell.label3.hidden=NO;
                        
                        cell.label3.tag=cell.num;
                        cell.label3.text=data.label3;
                        
                        if(data.hasLabel3Color && data.label3Color)
                        {
                            cell.label3.textColor=data.label3Color;
                        }
                        else
                        {
                            cell.label3.textColor=_label3Color;
                        }
                    }
                    else
                    {
                        cell.label3.hidden=YES;
                    }
                    
                    
                    if(_hasLabel4 && data.label4)//标签4
                    {
                        cell.label4.hidden=NO;
                        
                        cell.label4.tag=cell.num;
                        cell.label4.text=data.label4;
                        
                        if(data.hasLabel4Color && data.label4Color)
                        {
                            cell.label4.textColor=data.label4Color;
                        }
                        else
                        {
                            cell.label4.textColor=_label4Color;
                        }
                    }
                    else
                    {
                        cell.label4.hidden=YES;
                    }
                    
                    
                    if(_hasLabel5 && data.label5)//标签5
                    {
                        cell.label5.hidden=NO;
                        
                        cell.label5.tag=cell.num;
                        cell.label5.text=data.label5;
                        
                        if(data.hasLabel5Color && data.label5Color)
                        {
                            cell.label5.textColor=data.label5Color;
                        }
                        else
                        {
                            cell.label5.textColor=_label5Color;
                        }
                    }
                    else
                    {
                        cell.label5.hidden=NO;
                    }
                    
                    
                    if(_hasBackLabel && data.backLabel)//背部标签
                    {
                        cell.backLabel.hidden=NO;
                        
                        cell.backLabel.tag=cell.num;
                        cell.backLabel.text=data.backLabel;
                        
                        if(data.hasBackLabelColor && data.backLabelColor)
                        {
                            cell.backLabel.textColor=data.backLabelColor;
                        }
                        else
                        {
                            cell.backLabel.textColor=_backLabelColor;
                        }
                        
                        if(data.hasBackLabelFont && data.backLabelFont)
                        {
                            cell.backLabel.font=data.backLabelFont;
                        }
                        else
                        {
                            cell.backLabel.font=data.backLabelFont;
                        }
                        
                        if(data.hasBackLabelFrame)
                        {
                            cell.backLabel.frame=_backLabelFrame;
                        }
                    }
                    else
                    {
                        cell.backLabel.hidden=YES;
                    }
                    
                    
                    //左右移动归位
                    if(_canMoveLeft || _canMoveRight)
                    {
                        if(cell.state!=TABLE_CELL_STATE_READY)
                        {
                            [cell backToPositionWithAnimated:NO];
                        }
                    }
                    
                    //添加到列表视图
                    cell.frame=CGRectMake(0, _startPositionY+_cellMarginTop+(i+_dataArray.length)*(_cellHeight+_cellMarginInner), _cellWidth, _cellHeight);
                    
                    [self.scrollView addSubview:cell];
                }
            }
            
            //添加数据内容
            [_dataArray putArray:dataArray withIndex:_dataArray.length];
            
            //设置最后的cell内容y坐标
            _endPositionY=_startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom;
            
            //设置滚动视图内容大小
            if(_startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom+_bottomInsertHeight > self.scrollView.bounds.size.height)
            {
                self.scrollView.contentSize=CGSizeMake(self.scrollView.bounds.size.width, _startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom+_bottomInsertHeight);
            }
            else
            {
                self.scrollView.contentSize=CGSizeMake(self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
            }
            
            //刷新标记
            _isLoadingMore=YES;
            
            //滚动(加载更多过程中往上滚动则不改变位置)
            if(_scrollView.contentOffset.y >= self.scrollView.contentSize.height-(_cellHeight+_cellMarginInner)*dataArray.length-_cellMarginBottom-_pushFooterHeight-_scrollView.bounds.size.height)
            {
                if(_startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom+_bottomInsertHeight > self.scrollView.bounds.size.height)//显示的内容超过屏幕高度才需要调整
                {
                    if(_startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*dataArray.length+_cellMarginBottom > self.scrollView.bounds.size.height)//新添加的内容高于屏幕高度
                    {
                        [self.scrollView setContentOffset:CGPointMake(0, self.scrollView.contentSize.height-(_cellHeight+_cellMarginInner)*dataArray.length-_cellMarginBottom) animated:YES];//滚动到新添加的内容第一条
                    }
                    else//特殊情况需要借助刷新标记完成更新
                    {
                        [self.scrollView setContentOffset:CGPointMake(0, self.scrollView.contentSize.height-self.scrollView.bounds.size.height) animated:YES];//滚动到新添加的内容第一条
                    }
                }
            }

            
            //开启远程图片刷新
            [self startRemoteImageUpdating];
            
            loaded=YES;
        }
    }
    
    if(_hasPushFooter && _pushFooter)//回调
    {
        [_pushFooter finishLoadWithMessage:message];
    }
    
    //更新序号
    [self updateCellDataNum];
    
    _state=TABLE_STATE_READY;
    
    
    //解锁
    _pullHeader.locked=NO;
    _pushFooter.locked=NO;
    
}


//下拉
- (void)pullingHeader
{
    if(_hasPullHeader && _pullHeader && _state==TABLE_STATE_READY && _eventDelegate && [_eventDelegate respondsToSelector:@selector(tablePullToReload:)])
    {
        [_scrollView setContentOffset:CGPointMake(0, -_pullHeaderHeight) animated:NO];
        
        [_pullHeader headerStartLoad];
        
        [_eventDelegate tablePullToReload:self];
    }
}


//上推
- (void)pushingFooter
{
    if(_hasPushFooter && _pushFooter && _state==TABLE_STATE_READY && _eventDelegate && [_eventDelegate respondsToSelector:@selector(tablePushToMore:)])
    {
        [_scrollView setContentOffset:CGPointMake(0, (_scrollView.contentSize.height-_scrollView.bounds.size.height)+_pullHeaderHeight) animated:NO];
        
        [_pushFooter footerStartLoad];
        
        [_eventDelegate tablePushToMore:self];
    }
}



//滚动时
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{    
    //移动点
    self.lastPosition=self.currentPosition;
    self.currentPosition=scrollView.contentOffset;
    
    //判断移动方向
    if(_currentPosition.y>_lastPosition.y)
    {
//        if(_lastPosition.y<0)//触顶反弹
//        {
//            self.movingDirection=TABLE_MOVE_DOWN_BACK;
//        }
//        else
        {
            self.movingDirection=TABLE_MOVE_UP;
        }
        
        _scrollSpeed=(_currentPosition.y-_lastPosition.y)/(_cellHeight+_cellMarginInner);
        
        //滚动事件
        if(fabs(_currentPosition.y-_lastPosition.y)>4.0 && !_hasScrolledUp && _eventDelegate && [_eventDelegate respondsToSelector:@selector(tableViewDidScrollUp:)])
        {
            [_eventDelegate tableViewDidScrollUp:self];
            
            _hasScrolledUp=YES;
            _hasScrolledDown=NO;
        }
    }
    else if(_currentPosition.y<_lastPosition.y)
    {
//        if(_lastPosition.y>_scrollView.contentSize.height-_scrollView.bounds.size.height)//触底反弹
//        {
//            self.movingDirection=TABLE_MOVE_UP_BACK;
//        }
//        else
        {
            self.movingDirection=TABLE_MOVE_DOWN;
        }
        
        _scrollSpeed=(_lastPosition.y-_currentPosition.y)/(_cellHeight+_cellMarginInner);
        
        //滚动事件
        if(fabs(_currentPosition.y-_lastPosition.y)>4.0 && !_hasScrolledDown && _eventDelegate && [_eventDelegate respondsToSelector:@selector(tableViewDidScrollDown:)])
        {
            [_eventDelegate tableViewDidScrollDown:self];
            
            _hasScrolledDown=YES;
            _hasScrolledUp=NO;
        }
    }
    else
    {
        self.movingDirection=TABLE_MOVE_STOP;
    }
    
    if(scrollView.contentOffset.y>=0)// && scrollView.contentOffset.y<=_scrollView.contentSize.height-_scrollView.bounds.size.height)//正常滚动模式
    {
        //计算移动的单元格数
        self.cellOffset=(_currentPosition.y-_startPositionY-_cellMarginTop)/(_cellHeight+_cellMarginInner);
                
        //边界值修正（滑动过快时）
//        if(_cellOffset>_dataArray.length)
//        {
//            _cellOffset=_dataArray.length;
//        }
//        else if(_cellOffset<0)
//        {
//            _cellOffset=0;
//        }
        
        if(self.movingDirection==TABLE_MOVE_UP || _isLoadingMore)
        {
            if(_dataArray.length>_cellArray.length)//数据cell多于显示cell
            {
                if(_displayOffset+_cellsDisplayMax < _dataArray.length && (_cellOffset-_displayOffset) > (_cellsDisplayTimes/2*_cellsDisplayCount))//数据偏移量超过显示cell数量一半，则移动显示cell
                {
                    _changeDirection=TABLE_CHANGE_DOWN;
                    
                    //需要移动的cell个数
                    int movingCellCount=(_cellOffset-_displayOffset)-(_cellsDisplayTimes/2*_cellsDisplayCount);
                    
                    for(int i=0;i<movingCellCount;i++)
                    {
                        
                        KATTableCell *cell=(KATTableCell *)[_cellArray get:_displayOffset%_cellsDisplayMax];//需要移动的显示cell
                        KATTableCellData *data=(KATTableCellData *)[_dataArray get:_displayOffset+_cellsDisplayMax];//需要显示的数据
                        
                        [self changeCell:cell WithFrame:CGRectMake(0, _startPositionY+_cellMarginTop+(_displayOffset+_cellsDisplayMax)*(_cellHeight+_cellMarginInner), _cellWidth, _cellHeight) andData:data];//修改显示cell内容
                        
//                        NSLog(@"---- p:%i  num:%i, y=%.1f title:%@",_displayOffset%_cellsDisplayMax,cell.num,cell.frame.origin.y,cell.data.title);
                        
                        
                        _displayOffset++;
                        
                        if(_displayOffset+_cellsDisplayMax>=_dataArray.length)
                        {
                            break;
                        }
                        
                        //_cellsRemoved--;
                    }
                }
            }
            
            _isLoadingMore=NO;//加载更多标记，为了解决一些特殊情况（如加载内容较少）
        }
        else if(self.movingDirection==TABLE_MOVE_DOWN)
        {            
            if(_dataArray.length>_cellArray.length)//数据cell多于显示cell
            {
                if(_displayOffset>0 && (_cellOffset-_displayOffset) < (_cellsDisplayTimes/2*_cellsDisplayCount))//数据偏移量超过显示cell数量一半，则移动显示cell
                {
                    _changeDirection=TABLE_CHANGE_UP;
                    
                    //需要移动的cell个数
                    int movingCellCount=(_cellsDisplayTimes/2*_cellsDisplayCount)-(_cellOffset-_displayOffset);
                    
                    for(int i=0;i<movingCellCount;i++)
                    {
                        
                        KATTableCell *cell=(KATTableCell *)[_cellArray get:_displayOffset%_cellsDisplayMax==0?_cellsDisplayMax-1:_displayOffset%_cellsDisplayMax-1];//需要移动的显示cell
                        KATTableCellData *data=(KATTableCellData *)[_dataArray get:_displayOffset-1];//需要显示的数据
                        
                        [self changeCell:cell WithFrame:CGRectMake(0, _startPositionY+_cellMarginTop+(_displayOffset-1)*(_cellHeight+_cellMarginInner), _cellWidth, _cellHeight) andData:data];//修改显示cell内容
                        
//                        NSLog(@"---- p:%i  num:%i, y=%.1f title:%@",_displayOffset%_cellsDisplayMax==0?_cellsDisplayMax-1:_displayOffset%_cellsDisplayMax-1,cell.num,cell.frame.origin.y,cell.data.title);
                        
                        _displayOffset--;
                        
                        if(_displayOffset<=0)
                        {
                            break;
                        }
                    }
                }
            }
        }
    }
}


//滚动停止
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    //滚动事件标记
    _hasScrolledUp=NO;
    _hasScrolledDown=NO;
    
    _isLoadingMore=NO;//加载更多标记，为了解决一些特殊情况（如加载内容较少）
    
    //恢复滚动手势
    _scrollView.scrollEnabled=YES;
    
    //速度至0
    _scrollSpeed=0.0;
    
    if(_cellOffset==0 && _displayOffset>0)//回到头部却因为滑动速度过快显示cell没有调整回来
    {
        //需要移动的cell个数
        int movingCellCount=_displayOffset;
        
        for(int i=0;i<movingCellCount;i++)
        {
            
            KATTableCell *cell=(KATTableCell *)[_cellArray get:_displayOffset%_cellsDisplayMax==0?_cellsDisplayMax-1:_displayOffset%_cellsDisplayMax-1];//需要移动的显示cell
            KATTableCellData *data=(KATTableCellData *)[_dataArray get:_displayOffset-1];//需要显示的数据
            
            [self changeCell:cell WithFrame:CGRectMake(0, _startPositionY+_cellMarginTop+(_displayOffset-1)*(_cellHeight+_cellMarginInner), _cellWidth, _cellHeight) andData:data];//修改显示cell内容
            
            _displayOffset--;
            
            if(_displayOffset<=0)
            {
                break;
            }
        }
    }
    else if(_cellOffset>=_dataArray.length-_cellsDisplayCount && _displayOffset<_dataArray.length-_cellsDisplayMax)//回到底部却因为滑动速度过快显示cell没有调整回来
    {
        //需要移动的cell个数
        int movingCellCount=_dataArray.length-_cellsDisplayMax-_displayOffset;
        
        for(int i=0;i<movingCellCount;i++)
        {
            
            KATTableCell *cell=(KATTableCell *)[_cellArray get:_displayOffset%_cellsDisplayMax];//需要移动的显示cell
            KATTableCellData *data=(KATTableCellData *)[_dataArray get:_displayOffset+_cellsDisplayMax];//需要显示的数据
            
            [self changeCell:cell WithFrame:CGRectMake(0, _startPositionY+_cellMarginTop+(_displayOffset+_cellsDisplayMax)*(_cellHeight+_cellMarginInner), _cellWidth, _cellHeight) andData:data];//修改显示cell内容
            
            _displayOffset++;
            
            if(_displayOffset+_cellsDisplayMax >= _dataArray.length)
            {
                break;
            }
        }
    }
    
    //高速移动值重置
    for(int i=0;i<_cellArray.length;i++)
    {
        KATTableCell *cell=(KATTableCell *)[_cellArray get:i];
        cell.isHighSpeed=NO;
    }
}




//下拉开始加载(回调)
- (void)tableHeaderDidStartLoad:(KATTableHeader *)header
{
    //回调函数
    if(_hasPullHeader && _state!=TABLE_STATE_RELOAD && _state!=TABLE_STATE_MORE && _state!=TABLE_STATE_RELOAD_WAIT && _state!=TABLE_STATE_MORE_WAIT && _eventDelegate && [_eventDelegate respondsToSelector:@selector(tablePullToReload:)])
    {
        //加锁
        _pullHeader.locked=YES;
        _pushFooter.locked=YES;
        
        _state=TABLE_STATE_RELOAD_WAIT;
        
        [_eventDelegate tablePullToReload:self];
    }
}


//上推开始加载(回调)
- (void)tableFooterDidStartLoad:(KATTableFooter *)footer
{
    //回调函数
    if(_hasPushFooter && _state!=TABLE_STATE_RELOAD && _state!=TABLE_STATE_MORE && _state!=TABLE_STATE_RELOAD_WAIT && _state!=TABLE_STATE_MORE_WAIT && _eventDelegate && [_eventDelegate respondsToSelector:@selector(tablePushToMore:)])
    {
        //加锁
        _pullHeader.locked=YES;
        _pushFooter.locked=YES;
        
        _state=TABLE_STATE_MORE_WAIT;
        
        [_eventDelegate tablePushToMore:self];
    }
}


//修改显示cell的内容和位置
- (void)changeCell:(KATTableCell *)cell WithFrame:(CGRect)frame andData:(KATTableCellData *)data
{
    cell.data=data;
    cell.alpha=1.0f;
    
    cell.backLayer.tag=cell.num;
    cell.midLayer.tag=cell.num;
    cell.faceLayer.tag=cell.num;
    
    if(_hasBackButton1)
    {
        cell.backButton1.tag=cell.num;
    }
    
    if(_hasBackButton2)
    {
        cell.backButton2.tag=cell.num;
    }
    
    if(_hasBackButton3)
    {
        cell.backButton3.tag=cell.num;
    }
    
    if(_hasBackButton4)
    {
        cell.backButton4.tag=cell.num;
    }
    
    if(_hasBackButton5)
    {
        cell.backButton5.tag=cell.num;
    }
    
    if(_hasBackButton6)
    {
        cell.backButton6.tag=cell.num;
    }
    
    if(_hasBackButton7)
    {
        cell.backButton7.tag=cell.num;
    }
    
    if(_hasButton1)
    {
        cell.button1.tag=cell.num;
    }
    
    if(_hasButton2)
    {
        cell.button2.tag=cell.num;
    }
    
    if(_hasButton3)
    {
        cell.button3.tag=cell.num;
    }
    
    
    if(_hasBackBgColor)//有背面层背景色
    {
        if(data.hasBackBgColor && data.backBgColor)
        {
            cell.backLayer.backgroundColor=data.backBgColor;
        }
        else
        {
            cell.backLayer.backgroundColor=_backBgColor;
        }
    }
    
    if(_hasMidBgColor)//有中间层背景色
    {
        if(data.hasMidBgColor && data.midBgColor)
        {
            cell.midLayer.backgroundColor=data.midBgColor;
        }
        else
        {
            cell.midLayer.backgroundColor=_midBgColor;
        }
    }
    
    if(_hasFaceBgColor)//有表层背景色
    {
        if(data.hasFaceBgColor && data.faceBgColor)
        {
            cell.faceLayer.backgroundColor=data.faceBgColor;
        }
        else
        {
            cell.faceLayer.backgroundColor=_faceBgColor;
        }
    }
    
    
    /*
    if(_hasImage)//图片
    {
        if(data.hasImage)
        {
            cell.image.hidden=NO;
            
            cell.image.tag=cell.num;
            
            
            if(data.hasImageFrame)
            {
                cell.image.frame=data.imageFrame;
            }
            else
            {
                cell.image.frame=_imageFrame;
            }

            if(data.isImageReady && !data.isLoadImageFail)
            {
                if(data.hasImageMemory && data.image)
                {
    //                cell.image.image=data.image;
    //                [cell.image performSelector:@selector(setImage:) withObject:data.image];
    //                [cell.image performSelector:@selector(setImage:) withObject:data.image afterDelay:0.0 inModes:@[NSDefaultRunLoopMode]];
                    
                    if(_scrollSpeed>=_highScrollSpeed || cell.isHighSpeed)//高速滚动状态
                    {
                        cell.isHighSpeed=YES;
                        [cell.image performSelector:@selector(setImage:) withObject:data.image afterDelay:0.05f inModes:@[NSDefaultRunLoopMode]];
                    }
                    else
                    {
                        [cell.image performSelector:@selector(setImage:) withObject:data.image];
                    }
                    
                }
                else if(data.imagePath)
                {
    //                cell.image.image=[UIImage imageWithContentsOfFile:data.imagePath];
    //                [cell.image performSelector:@selector(setImage:) withObject:[UIImage imageWithContentsOfFile:data.imagePath]];
    //                [cell.image performSelector:@selector(setImage:) withObject:[UIImage imageWithContentsOfFile:data.imagePath] afterDelay:0.0 inModes:@[NSDefaultRunLoopMode]];
                    
                    if(_scrollSpeed>=_highScrollSpeed || cell.isHighSpeed)//高速滚动状态
                    {
                        cell.isHighSpeed=YES;
                        [cell.image performSelector:@selector(setImage:) withObject:[UIImage imageWithContentsOfFile:data.imagePath] afterDelay:0.05f inModes:@[NSDefaultRunLoopMode]];
                    }
                    else
                    {
                        [cell.image performSelector:@selector(setImage:) withObject:[UIImage imageWithContentsOfFile:data.imagePath]];
                    }
                }
                else
                {
                    cell.image=nil;
                }
            }
            else
            {
                if(_hasCacheImage && _cacheImage)// && cell.image.image!=_cacheImage)
                {
    //                cell.image.image=_cacheImage;
    //                [cell.image performSelector:@selector(setImage:) withObject:_cacheImage];
    //                [cell.image performSelector:@selector(setImage:) withObject:_cacheImage afterDelay:0.0 inModes:@[NSDefaultRunLoopMode]];
                    
                    if(_scrollSpeed>=_highScrollSpeed)//高速滚动中
                    {
                        [cell.image performSelector:@selector(setImage:) withObject:_cacheImage afterDelay:0.05f inModes:@[NSDefaultRunLoopMode]];
                    }
                    else
                    {
                        [cell.image performSelector:@selector(setImage:) withObject:_cacheImage];
                    }
                }
                else
                {
                    cell.image.image=nil;
//                    cell.image.hidden=YES;
                }
                
                if(_isRemoteImage && !_isRemoteImageUpdateTimerWorking)//启动远程图片线程
                {
                    _isRemoteImageUpdateTimerWorking=YES;
                    self.remoteImageUpdateTimer=[NSTimer scheduledTimerWithTimeInterval:_remoteImageUpdateInterval target:self selector:@selector(remoteImageUpdate) userInfo:nil repeats:YES];
                }
            }
        }
        else
        {
            cell.image.hidden=YES;
        }
    }
    */
    
    
    if(_hasImage)//图片
    {
        if(data.hasImage)
        {
            cell.image.hidden=NO;
            
            cell.image.tag=cell.num;
            
            
            if(data.hasImageFrame)
            {
                cell.image.frame=data.imageFrame;
            }
            else
            {
                cell.image.frame=_imageFrame;
            }
            
            if(data.isImageReady && !data.isLoadImageFail)
            {
                if(data.hasImageMemory && data.image)
                {
                    cell.image.image=data.image;
                }
                else if(data.imagePath)
                {
                    //异步加载解压图片
                    dispatch_async(_queueImage, ^
                    {
                        //加载
                        UIImage *image=[UIImage imageWithContentsOfFile:data.imagePath];
                        
                        __block CGSize size=CGSizeZero;
                        
                        dispatch_sync(dispatch_get_main_queue(), ^
                        {
                            size=cell.image.bounds.size;
                        });
                        
                        //压缩并适配尺寸
                        image=[KATImageUtil fitImage:image withSize:size andScale:0];
                        
                        //显示
                        dispatch_sync(dispatch_get_main_queue(), ^
                        {
                            [cell.image performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO modes:@[NSRunLoopCommonModes]];
                        });
                    });
                }
            }
            else
            {
                if(_hasCacheImage && _cacheImage)
                {
                    cell.image.image=_cacheImage;
                }
                else
                {
                    cell.image.image=nil;
                }
                
                //开启远程图片刷新
                [self startRemoteImageUpdating];
            }
        }
        else
        {
            cell.image.hidden=YES;
        }
    }
    
    
    if(_hasImage2)//图片2
    {
        if(data.hasImage2)
        {
            cell.image2.hidden=NO;
            
            cell.image2.tag=cell.num;
            
            
            if(data.hasImage2Frame)
            {
                cell.image2.frame=data.image2Frame;
            }
            else
            {
                cell.image2.frame=_image2Frame;
            }
            
            if(data.isImage2Ready && !data.isLoadImage2Fail)
            {
                if(data.hasImage2Memory && data.image2)
                {
                    cell.image2.image=data.image2;
                }
                else if(data.image2Path)
                {
                    //异步加载解压图片
                    dispatch_async(_queueImage2, ^
                    {
                        //加载
                        UIImage *image=[UIImage imageWithContentsOfFile:data.image2Path];
                        
                        __block CGSize size=CGSizeZero;
                        
                        dispatch_sync(dispatch_get_main_queue(), ^
                        {
                            size=cell.image2.bounds.size;
                        });
                        
                        //压缩并适配尺寸
                        image=[KATImageUtil fitImage:image withSize:size andScale:0];
                        
                        //显示
                        dispatch_sync(dispatch_get_main_queue(), ^
                        {
                            [cell.image2 performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO modes:@[NSRunLoopCommonModes]];
                        });
                    });
                }
            }
            else
            {
                if(_hasCacheImage && _cacheImage)
                {
                    cell.image2.image=_cacheImage;
                }
                else
                {
                    cell.image2.image=nil;
                }
                
                //开启远程图片刷新
                [self startRemoteImageUpdating];
            }
        }
        else
        {
            cell.image2.hidden=YES;
        }
    }
    
    
    if(_hasImage3)//图片3
    {
        if(data.hasImage3)
        {
            cell.image3.hidden=NO;
            
            cell.image3.tag=cell.num;
            
            
            if(data.hasImage3Frame)
            {
                cell.image3.frame=data.image3Frame;
            }
            else
            {
                cell.image3.frame=_image3Frame;
            }
            
            if(data.isImage3Ready && !data.isLoadImage3Fail)
            {
                if(data.hasImage3Memory && data.image3)
                {
                    cell.image3.image=data.image3;
                }
                else if(data.image3Path)
                {
                    //异步加载解压图片
                    dispatch_async(_queueImage3, ^
                    {
                        //加载
                        UIImage *image=[UIImage imageWithContentsOfFile:data.image3Path];
                        
                        __block CGSize size=CGSizeZero;
                        
                        dispatch_sync(dispatch_get_main_queue(), ^
                        {
                            size=cell.image3.bounds.size;
                        });
                        
                        //压缩并适配尺寸
                        image=[KATImageUtil fitImage:image withSize:size andScale:0];
                        
                        //显示
                        dispatch_sync(dispatch_get_main_queue(), ^
                        {
                            [cell.image3 performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO modes:@[NSRunLoopCommonModes]];
                        });
                    });
                }
            }
            else
            {
                if(_hasCacheImage && _cacheImage)
                {
                    cell.image3.image=_cacheImage;
                }
                else
                {
                    cell.image3.image=nil;
                }
                
                //开启远程图片刷新
                [self startRemoteImageUpdating];
            }
        }
        else
        {
            cell.image3.hidden=YES;
        }
    }
    
    if(_hasTitle && data.title)//标题
    {
        cell.title.hidden=NO;
        
        cell.title.tag=cell.num;
        cell.title.text=data.title;
        
        if(data.hasTitleColor && data.titleColor)
        {
            cell.title.textColor=data.titleColor;
        }
        else
        {
            cell.title.textColor=_titleColor;
        }
        
        if(data.hasTitleFont && data.titleFont)
        {
            cell.title.font=data.titleFont;
        }
        else
        {
            cell.title.font=_titleFont;
        }
        
        if(data.hasTitleFrame)
        {
            cell.title.frame=data.titleFrame;
        }
        else
        {
            cell.title.frame=_titleFrame;
        }
    }
    else
    {
        cell.title.hidden=YES;
    }
    
    
    if(_hasContent && data.content)//内容
    {
        cell.content.hidden=NO;
        
        cell.content.tag=cell.num;
        cell.content.text=data.content;
        
        if(data.hasContentColor && data.contentColor)
        {
            cell.content.textColor=data.contentColor;
        }
        else
        {
            cell.content.textColor=_contentColor;
        }
        
        if(data.hasContentFont && data.contentFont)
        {
            cell.content.font=data.contentFont;
        }
        else
        {
            cell.content.font=_contentFont;
        }
        
        if(data.hasContentFrame)
        {
            cell.content.frame=data.contentFrame;
        }
        else
        {
            cell.content.frame=_contentFrame;
        }
    }
    else
    {
        cell.content.hidden=YES;
    }
    
    
    if(_hasRichTitle && data.richTitle)//富文本标题
    {
        cell.richTitle.hidden=NO;
        
        cell.richTitle.tag=cell.num;
        cell.richTitle.text=data.richTitle;
        
        if(data.hasRichTitleStyle && data.richTitleStyle)
        {
            cell.richTitle.style=data.richTitleStyle;
        }
        else
        {
            cell.richTitle.style=_richTitleStyle;
        }
        
        if(data.hasRichTitleFrame)
        {
            cell.richTitle.frame=data.richTitleFrame;
        }
        else
        {
            cell.richTitle.frame=_richTitleFrame;
        }
    }
    else
    {
        cell.richTitle.hidden=YES;
    }
    
    
    if(_hasRichContent && data.richContent)//富文本内容
    {
        cell.richContent.hidden=NO;
        
        cell.richContent.tag=cell.num;
        cell.richContent.text=data.richContent;
        
        if(data.hasRichContentStyle && data.richContentStyle)
        {
            cell.richContent.style=data.richContentStyle;
        }
        else
        {
            cell.richContent.style=_richContentStyle;
        }
        
        if(data.hasRichContentFrame)
        {
            cell.richContent.frame=data.richContentFrame;
        }
        else
        {
            cell.richContent.frame=_richContentFrame;
        }
    }
    else
    {
        cell.richContent.hidden=YES;
    }
    
    
    if(_hasRichLabel && data.richLabel)//富文本标签
    {
        cell.richLabel.hidden=NO;
        
        cell.richLabel.tag=cell.num;
        cell.richLabel.text=data.richLabel;
    }
    else
    {
        cell.richLabel.hidden=YES;
    }
    
    
    if(_hasText && data.text)//文本
    {
        cell.text.hidden=NO;
        
        cell.text.tag=cell.num;
        cell.text.text=data.text;
        
        if(data.hasTextColor && data.textColor)
        {
            cell.text.textColor=data.textColor;
        }
        else
        {
            cell.text.textColor=_textColor;
        }
        
        if(data.hasTextBgColor && data.textBgColor)
        {
            cell.text.backgroundColor=data.textBgColor;
        }
        else
        {
            cell.text.backgroundColor=_textBgColor;
        }
        
        if(data.hasTextFont && data.textFont)
        {
            cell.text.font=data.textFont;
        }
        else
        {
            cell.text.font=_textFont;
        }
        
        if(data.hasTextFrame)
        {
            cell.text.frame=data.textFrame;
        }
        else
        {
            cell.text.frame=_textFrame;
        }
    }
    else
    {
        cell.text.hidden=YES;
    }
    
    
    if(_hasBadge)//徽标
    {
        cell.badge.tag=cell.num;
        
        if(data.hasBadge && data.badge)
        {
            cell.badge.text=data.badge;
            cell.badge.hidden=NO;
            
            if(data.hasBadgeBgColor && data.badgeBgColor)
            {
                cell.badge.backgroundColor=data.badgeBgColor;
            }
            else
            {
                cell.badge.backgroundColor=_badgeBgColor;//默认颜色
            }
            
            if(data.hasBadgeTextColor && data.badgeTextColor)
            {
                cell.badge.textColor=data.badgeTextColor;
            }
            else
            {
                cell.badge.textColor=_badgeTextColor;//默认颜色
            }
            
            if(_hasBadgeBorder)//边界颜色
            {
                cell.badge.layer.borderColor=_badgeBorderColor.CGColor;
                
                if(data.hasBadgeBorderColor && data.badgeBorderColor)
                {
                    cell.badge.layer.borderColor=data.badgeBorderColor.CGColor;
                }
            }
            
            if(data.hasBadgeFrame)
            {
                cell.badge.frame=data.badgeFrame;
            }
            else
            {
                cell.badge.frame=_badgeFrame;
            }
        }
        else
        {
            cell.badge.hidden=YES;
        }
    }
    
    
    if(_hasSpButton)//特殊按钮
    {
        cell.spButton.tag=cell.num;
        
        if(data.hasSpButton && data.spButtonColor)
        {
            cell.spButton.hidden=NO;

            cell.spButton.type=data.spButtonType;
            cell.spButton.color=data.spButtonColor;
            cell.spButton.lineWidth=data.spButtonLineWidth;
            cell.spButton.scale=data.spButtonScale;
            
            cell.spButton.frame=data.spButtonFrame;
        }
        else
        {
            cell.spButton.hidden=YES;
        }
    }
    
    
    if(_hasLabel1 && data.label1)//标签1
    {
        cell.label1.hidden=NO;
        
        cell.label1.tag=cell.num;
        cell.label1.text=data.label1;
        
        if(data.hasLabel1Color && data.label1Color)
        {
            cell.label1.textColor=data.label1Color;
        }
        else
        {
            cell.label1.textColor=_label1Color;
        }
    }
    else
    {
        cell.label1.hidden=YES;
    }
    
    
    if(_hasLabel2 && data.label2)//标签2
    {
        cell.label2.hidden=NO;
        
        cell.label2.tag=cell.num;
        cell.label2.text=data.label2;
        
        if(data.hasLabel2Color && data.label2Color)
        {
            cell.label2.textColor=data.label2Color;
        }
        else
        {
            cell.label2.textColor=_label2Color;
        }
    }
    else
    {
        cell.label2.hidden=YES;
    }
    
    
    if(_hasLabel3 && data.label3)//标签3
    {
        cell.label3.hidden=NO;
        
        cell.label3.tag=cell.num;
        cell.label3.text=data.label3;
        
        if(data.hasLabel3Color && data.label3Color)
        {
            cell.label3.textColor=data.label3Color;
        }
        else
        {
            cell.label3.textColor=_label3Color;
        }
    }
    else
    {
        cell.label3.hidden=YES;
    }
    
    
    if(_hasLabel4 && data.label4)//标签4
    {
        cell.label4.hidden=NO;
        
        cell.label4.tag=cell.num;
        cell.label4.text=data.label4;
        
        if(data.hasLabel4Color && data.label4Color)
        {
            cell.label4.textColor=data.label4Color;
        }
        else
        {
            cell.label4.textColor=_label4Color;
        }
    }
    else
    {
        cell.label4.hidden=YES;
    }
    
    
    if(_hasLabel5 && data.label5)//标签5
    {
        cell.label5.hidden=NO;
        
        cell.label5.tag=cell.num;
        cell.label5.text=data.label5;
        
        if(data.hasLabel5Color && data.label5Color)
        {
            cell.label5.textColor=data.label5Color;
        }
        else
        {
            cell.label5.textColor=_label5Color;
        }
    }
    else
    {
        cell.label5.hidden=NO;
    }
    
    
    if(_hasBackLabel && data.backLabel)//背部标签
    {
        cell.backLabel.hidden=NO;
        
        cell.backLabel.tag=cell.num;
        cell.backLabel.text=data.backLabel;
        
        if(data.hasBackLabelColor && data.backLabelColor)
        {
            cell.backLabel.textColor=data.backLabelColor;
        }
        else
        {
            cell.backLabel.textColor=_backLabelColor;
        }
        
        if(data.hasBackLabelFont && data.backLabelFont)
        {
            cell.backLabel.font=data.backLabelFont;
        }
        else
        {
            cell.backLabel.font=data.backLabelFont;
        }
        
        if(data.hasBackLabelFrame)
        {
            cell.backLabel.frame=_backLabelFrame;
        }
    }
    else
    {
        cell.backLabel.hidden=YES;
    }
    
    
    if(_canMoveLeft || _canMoveRight)//左右移判断
    {
        if(cell.state!=cell.data.state)
        {
            if(cell.data.state==TABLE_CELL_STATE_READY)
            {
                [cell backToPositionWithAnimated:NO];
            }
            else if(cell.data.state==TABLE_CELL_STATE_LEFT)
            {
                [cell moveLeftWithDistance:_leftMovingDst andAnimated:NO];
            }
            else if(cell.data.state==TABLE_CELL_STATE_RIGHT)
            {
                [cell moveRightWithDistance:_rightMovingDst andAnimated:NO];
            }
        }
    }
    
    
    //添加到列表视图
    cell.frame=frame;    
}


//刷新列表
- (void)updateTable
{
    for(int i=0;i<_cellArray.length && i<_dataArray.length;i++)
    {
        KATTableCell *cell=(KATTableCell *)[_cellArray get:i];
        
        [self changeCell:cell WithFrame:cell.frame andData:cell.data];
    }
}


//启动远程图片更新
- (void)startRemoteImageUpdating
{
    if(_isRemoteImage && !_isRemoteImageUpdateTimerWorking)//启动远程图片线程
    {
        _isRemoteImageUpdateTimerWorking=YES;
        self.remoteImageUpdateTimer=[NSTimer scheduledTimerWithTimeInterval:_remoteImageUpdateInterval target:self selector:@selector(remoteImageUpdate) userInfo:nil repeats:YES];
        
        [[NSRunLoop mainRunLoop] addTimer:_remoteImageUpdateTimer forMode:NSRunLoopCommonModes];
    }
    
}


//远程图片加载更新扫描
- (void)remoteImageUpdate
{
    BOOL finish=YES;//完成标记
    
    for(int i=0;i<_cellArray.length;i++)
    {
        KATTableCell *cell=(KATTableCell *)[_cellArray get:i];
        
        if(_hasImage && cell.data.hasImage && cell.data.isCacheImage)//正在使用缓冲图
        {
            if(_hasImage && cell.data.hasImage && cell.data.isCacheImage)//正在使用缓冲图
            {
                if(cell.data.isImageReady)//图片已经加载完成
                {
                    if(cell.data.hasImageMemory && cell.data.image)
                    {
                        cell.image.image=cell.data.image;
                    }
                    else if(cell.data.imagePath)
                    {
                        //异步加载解压图片
                        dispatch_async(_queueImage, ^
                        {
                            //加载
                            UIImage *image=[UIImage imageWithContentsOfFile:cell.data.imagePath];
                            
                            __block CGSize size=CGSizeZero;
                            
                            dispatch_sync(dispatch_get_main_queue(), ^
                            {
                                size=cell.image.bounds.size;
                            });
                            
                            //压缩并适配尺寸
                            image=[KATImageUtil fitImage:image withSize:size andScale:0];
                           
                            //显示
                            dispatch_sync(dispatch_get_main_queue(), ^
                            {
                                [cell.image performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO modes:@[NSRunLoopCommonModes]];
                            });
                        });
                    }
                }
                else//未完成
                {
                    finish=NO;
                }
            }
            
            if(_hasImage2 && cell.data.hasImage2 && cell.data.isCacheImage2)//正在使用缓冲图2
            {
                if(cell.data.isImage2Ready)//图片2已经加载完成
                {
                    if(cell.data.hasImage2Memory && cell.data.image2)
                    {
                        cell.image2.image=cell.data.image2;
                    }
                    else if(cell.data.image2Path)
                    {
                        //异步加载解压图片
                        dispatch_async(_queueImage2, ^
                        {
                            //加载
                            UIImage *image=[UIImage imageWithContentsOfFile:cell.data.image2Path];
                            
                            __block CGSize size=CGSizeZero;
                            
                            dispatch_sync(dispatch_get_main_queue(), ^
                            {
                                size=cell.image2.bounds.size;
                            });
                            
                            //压缩并适配尺寸
                            image=[KATImageUtil fitImage:image withSize:size andScale:0];
                            
                            //显示
                            dispatch_sync(dispatch_get_main_queue(), ^
                            {
                                [cell.image2 performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO modes:@[NSRunLoopCommonModes]];
                            });
                        });
                    }
                }
                else//未完成
                {
                    finish=NO;
                }
            }
            
            if(_hasImage3 && cell.data.hasImage3 && cell.data.isCacheImage3)//正在使用缓冲图3
            {
                if(cell.data.isImage3Ready)//图片3已经加载完成
                {
                    if(cell.data.hasImage3Memory && cell.data.image3)
                    {
                        cell.image3.image=cell.data.image3;
                    }
                    else if(cell.data.image3Path)
                    {
                        //异步加载解压图片
                        dispatch_async(_queueImage3, ^
                        {
                            //加载
                            UIImage *image=[UIImage imageWithContentsOfFile:cell.data.image3Path];
                            
                            __block CGSize size=CGSizeZero;
                            
                            dispatch_sync(dispatch_get_main_queue(), ^
                            {
                                size=cell.image3.bounds.size;
                            });
                            
                            //压缩并适配尺寸
                            image=[KATImageUtil fitImage:image withSize:size andScale:0];
                            
                            //显示
                            dispatch_sync(dispatch_get_main_queue(), ^
                            {
                                [cell.image3 performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO modes:@[NSRunLoopCommonModes]];
                            });
                        });
                    }
                }
                else//未完成
                {
                    finish=NO;
                }
            }

        }
    }
    if(finish && _isRemoteImageUpdateTimerWorking && _remoteImageUpdateTimer)//取消定时器
    {
        [_remoteImageUpdateTimer invalidate];
        self.remoteImageUpdateTimer=nil;
        
        _isRemoteImageUpdateTimerWorking=NO;
    }
}



#pragma - mark Cell内部事件

//左滑动
- (void)leftSwipe:(UISwipeGestureRecognizer *)recognizer
{
    if(_canMoveLeft || _canMoveRight)
    {
        KATTableCell *cell=(KATTableCell *)[_cellArray get:(int)recognizer.view.tag];
        
        if(cell.state==TABLE_CELL_STATE_RIGHT)
        {
            [cell backToPositionWithAnimated:YES];
        }
        else if(cell.state==TABLE_CELL_STATE_READY && _canMoveLeft)
        {
            [cell moveLeftWithDistance:_leftMovingDst andAnimated:YES];
        }
    }
}


//右滑动
- (void)rightSwipe:(UISwipeGestureRecognizer *)recognizer
{
    if(_canMoveLeft || _canMoveRight)
    {
        KATTableCell *cell=(KATTableCell *)[_cellArray get:(int)recognizer.view.tag];
        
        if(cell.state==TABLE_CELL_STATE_LEFT)
        {
            [cell backToPositionWithAnimated:YES];
        }
        else if(cell.state==TABLE_CELL_STATE_READY && _canMoveRight)
        {
            [cell moveRightWithDistance:_rightMovingDst andAnimated:YES];
        }
    }
}


//拖动
- (void)cellPan:(UIPanGestureRecognizer *)recognizer
{
    if(_canMoveLeft || _canMoveRight)
    {
        //判断是否传递拖动事件
        float distY=fabs([recognizer translationInView:self].y)+0.5;//上下滚动的距离
        float distX=fabs([recognizer translationInView:self].x)+0.5;//左右移动的距离
        
        if(distX/distY>2.5)
        {
            _cellPanDisabled=NO;
            _isScrollDisabled=YES;
        }
        else
        {
            _cellPanDisabled=YES;
            _isScrollDisabled=NO;
        }
        
//        NSLog(@"x=%.1f,y=%.1f,z=%.1f",distX,distY,distX/distY);
        
        KATTableCell *cell=(KATTableCell *)[_cellArray get:(int)recognizer.view.tag];
        
        if(!_cellPanDisabled || cell.state==TABLE_CELL_STATE_MOVING)
        {
            if(recognizer.state==UIGestureRecognizerStateBegan)//开始
            {
                if(cell.state==TABLE_CELL_STATE_READY)
                {
                    cell.state=TABLE_CELL_STATE_MOVING;
                    cell.data.state=TABLE_CELL_STATE_MOVING;
                    cell.value=recognizer.view.frame.origin.x;//保存初始位置
                }
                else
                {
                    [cell backToPositionWithAnimated:YES];
                }
            }
            if(recognizer.state==UIGestureRecognizerStateEnded || recognizer.state==UIGestureRecognizerStateFailed)//结束或者失败
            {
                if(cell.state==TABLE_CELL_STATE_MOVING)
                {
                    cell.value=0;
                    
                    if(recognizer.view.frame.origin.x<-_leftMovingDst*0.62)//左移动
                    {
                        [cell moveLeftWithDistance:_leftMovingDst andAnimated:YES];
                    }
                    else if(recognizer.view.frame.origin.x>_rightMovingDst*0.62)//右移
                    {
                        [cell moveRightWithDistance:_rightMovingDst andAnimated:YES];
                    }
                    else
                    {
                        [cell backToPositionWithAnimated:YES];
                    }
                }
                
                _isScrollDisabled=NO;
            }
            else if(cell.state==TABLE_CELL_STATE_MOVING)//拖动过程
            {
                float dis=[recognizer translationInView:recognizer.view].x+cell.value;//移动的距离
                
                float left=_canMoveLeft?-_leftMovingDst-_leftMovingFlexibleDst:0.0;//最左端
                float right=_canMoveRight?_rightMovingDst+_rightMovingFlexibleDst:0.0;//最右端
                
                if(dis<left)
                {
                    dis=left;
                }
                
                if(dis>right)
                {
                    dis=right;
                }
                
                recognizer.view.frame=CGRectMake(dis, recognizer.view.frame.origin.y, recognizer.view.frame.size.width, recognizer.view.frame.size.height);
            }
        }
    }
}


//背面层扫动
- (void)backLayerPan:(UIPanGestureRecognizer *)recognizer
{
    if(_canMoveLeft || _canMoveRight)
    {
        KATTableCell *cell=(KATTableCell *)[_cellArray get:(int)recognizer.view.tag];
        
        if(cell.state==TABLE_CELL_STATE_LEFT || cell.state==TABLE_CELL_STATE_RIGHT)
        {
            [cell backToPositionWithAnimated:YES];
        }
    }
}


//单元格背景点击(左右滑动后，输入法等，恢复原来位置)
- (void)backgroundTap:(UIGestureRecognizer *)recognizer
{
    if(_canMoveLeft || _canMoveRight)
    {
        KATTableCell *cell=(KATTableCell *)[_cellArray get:(int)recognizer.view.tag];
        
        if(cell.state!=TABLE_CELL_STATE_READY)
        {
            [cell backToPositionWithAnimated:YES];
        }
    }
    
    //关闭键盘
    if(_hasText && _textCanEdit)
    {
        for(int i=0;i<_cellArray.length;i++)
        {
            KATTableCell *cell=(KATTableCell *)[_cellArray get:i];
            
            if(cell.text)
            {
                [cell.text resignFirstResponder];
            }
        }
    }
}




//拖动事件传递
//- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
//{
//    if(_cellPanDisabled)
//    {
//        _cellPanDisabled=NO;
//        
//        return NO;
//    }
//    else
//    {
//        return YES;
//    }
//}


//事件同时传递给其他View
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    if([otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]])//只传递给拖动手势
    {
        if(_isScrollDisabled)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else
    {
        return NO;
    }
}


#pragma - mark Cell操作


//所有的Cell都左移
- (void)allCellsMoveLeftWithAnimated:(BOOL)animated
{
    for(int i=0;i<_dataArray.length;i++)
    {
        KATTableCellData *data=(KATTableCellData *)[_dataArray get:i];
        
        data.state=TABLE_CELL_STATE_LEFT;
    }
    
    for(int i=0;i<_cellArray.length;i++)
    {
        KATTableCell *cell=(KATTableCell *)[_cellArray get:i];
        
        [cell moveLeftWithDistance:_leftMovingDst andAnimated:animated];
    }
}


//所有的Cell都右移
- (void)allCellsMoveRightWithAnimated:(BOOL)animated
{
    for(int i=0;i<_dataArray.length;i++)
    {
        KATTableCellData *data=(KATTableCellData *)[_dataArray get:i];
        
        data.state=TABLE_CELL_STATE_RIGHT;
    }
    
    for(int i=0;i<_cellArray.length;i++)
    {
        KATTableCell *cell=(KATTableCell *)[_cellArray get:i];
        
        [cell moveRightWithDistance:_rightMovingDst andAnimated:animated];
    }
}


//所有的Cell都回到原位
- (void)allCellsBackToPositionWithAnimated:(BOOL)animated
{
    for(int i=0;i<_dataArray.length;i++)
    {
        KATTableCellData *data=(KATTableCellData *)[_dataArray get:i];
        
        data.state=TABLE_CELL_STATE_READY;
    }
    
    for(int i=0;i<_cellArray.length;i++)
    {
        KATTableCell *cell=(KATTableCell *)[_cellArray get:i];
        
        [cell backToPositionWithAnimated:animated];
    }
}



//更新数据数组中的num
- (void)updateCellDataNum
{
    for(int i=0;i<_dataArray.length;i++)
    {
        KATTableCellData *data=(KATTableCellData *)[_dataArray get:i];
        
        data.num=i;
    }
}




//更新cell中的num及tag
- (void)updateCell:(KATTableCell *)cell withNum:(int)num
{
    if(cell)
    {
        cell.num=num;
        
        cell.tag=num;
        cell.backLayer.tag=cell.num;
        cell.midLayer.tag=cell.num;
        cell.faceLayer.tag=cell.num;
        
        if(_hasBackButton1)
        {
            cell.backButton1.tag=cell.num;
        }
        
        if(_hasBackButton2)
        {
            cell.backButton2.tag=cell.num;
        }
        
        if(_hasBackButton3)
        {
            cell.backButton3.tag=cell.num;
        }
        
        if(_hasBackButton4)
        {
            cell.backButton4.tag=cell.num;
        }
        
        if(_hasBackButton5)
        {
            cell.backButton5.tag=cell.num;
        }
        
        if(_hasBackButton6)
        {
            cell.backButton6.tag=cell.num;
        }
        
        if(_hasBackButton7)
        {
            cell.backButton7.tag=cell.num;
        }
        
        if(_hasButton1)
        {
            cell.button1.tag=cell.num;
        }
        
        if(_hasButton2)
        {
            cell.button2.tag=cell.num;
        }
        
        if(_hasButton3)
        {
            cell.button3.tag=cell.num;
        }
        
        if(_hasImage)//图片
        {
            cell.image.tag=cell.num;
        }
        
        if(_hasImage2)//图片2
        {
            cell.image2.tag=cell.num;
        }
        
        if(_hasImage3)//图片3
        {
            cell.image3.tag=cell.num;
        }
        
        if(_hasTitle)//标题
        {
            cell.title.tag=cell.num;
        }
        
        if(_hasContent)//内容
        {
            cell.content.tag=cell.num;
        }
        
        if(_hasRichTitle)//富文本标题
        {
            cell.richTitle.tag=cell.num;
        }
        
        if(_hasRichContent)//富文本内容
        {
            cell.richContent.tag=cell.num;
        }
        
        if(_hasBadge)//徽标
        {
            cell.badge.tag=cell.num;
        }
        
        if(_hasLabel1)//标签1
        {
            cell.label1.tag=cell.num;
        }
        
        if(_hasLabel2)//标签2
        {
            cell.label2.tag=cell.num;
        }
        
        if(_hasLabel3)//标签3
        {
            cell.label3.tag=cell.num;
        }
        
        if(_hasLabel4)//标签4
        {
            cell.label4.tag=cell.num;
        }
        
        if(_hasLabel5)//标签5
        {
            cell.label5.tag=cell.num;
        }
        
        if(_hasBackLabel)//背部标签
        {
            cell.backLabel.tag=cell.num;
        }
        
        if(_hasText)//文本
        {
            cell.text.tag=cell.num;
        }
        
        if(_hasSpButton)//特殊按钮
        {
            cell.spButton.tag=cell.num;
        }
    }
}


//删除cell
- (void)removeCell:(KATTableCell *)cell
{
    if(_state==TABLE_STATE_READY && cell)
    {
        if(_eventDelegate && [_eventDelegate respondsToSelector:@selector(tableView:beginRemoveCell:)])
        {
            [_eventDelegate tableView:self beginRemoveCell:cell];
        }
        
        //改变状态
        _state=TABLE_STATE_REMOVE;
        
        //停止滑动
        _scrollView.scrollEnabled=NO;
        
        //在data数组中删除该数据
        [_dataArray deleteMember:cell.data];
        
        _cellsRemoved++;
        
        //更新数组的num
        [self updateCellDataNum];
        
        //cell设置为最前
//        [_scrollView bringSubviewToFront:cell];
        
        //动画
        [UIView animateWithDuration:_cellRemoveTime animations:^//cell左侧滑动消失
        {
            cell.midLayer.frame=CGRectMake(0, 0, cell.midLayer.bounds.size.width, cell.midLayer.bounds.size.height);
            cell.frame=CGRectMake(-cell.bounds.size.width, cell.frame.origin.y, cell.bounds.size.width, cell.bounds.size.height);
            cell.alpha=0.4f;
        }
        completion:^(BOOL finished)
        {
            cell.alpha=0.0f;
            
            cell.state=TABLE_CELL_STATE_READY;
            cell.data.state=TABLE_CELL_STATE_READY;
            cell.data=nil;
            
            //辅助变量
            KATTableCell *topCell=[_cellArray get:_displayOffset%_cellArray.length];
            KATTableCell *bottomCell=[_cellArray get:_displayOffset%_cellArray.length>0?_displayOffset%_cellArray.length-1:_cellArray.length-1];
            __block int cellNum=[_cellArray indexWithMember:cell];//被删除的cell的位置
            __block double bottomY=bottomCell.frame.origin.y;//显示cell数组中最下面的一个y坐标
            __block int bottomNum=_displayOffset%_cellArray.length>0?_displayOffset%_cellArray.length-1:_cellArray.length-1;//最后一个显示cell的num
            __block int bottomData=bottomCell.data.num;//最后一个显示cell所带的data的num
            __block double topY=topCell.frame.origin.y;//显示cell数组中最上面的一个y坐标
            __block int topNum=_displayOffset%_cellArray.length;//第一个显示cell的num
            __block int topData=topCell.data.num;//第一个显示cell所带的data的num
                        
            [UIView animateWithDuration:_cellRemoveTime*0.5 animations:^//cell下面的cells全部上移
            {
                for(int i=0;i<_cellArray.length;i++)
                {
                    KATTableCell *c=(KATTableCell *)[_cellArray get:i];

                    if(c.frame.origin.y>cell.frame.origin.y)
                    {
                        c.frame=CGRectMake(0, c.frame.origin.y-c.bounds.size.height-_cellMarginInner, c.bounds.size.width, c.bounds.size.height);
                    }
                }
            }
            completion:^(BOOL finished)
            {
                if(bottomY+(_cellHeight+_cellMarginInner) < _startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*(_dataArray.length+1))
                {
                    [_cellArray deleteMember:cell];
                    [_cellArray put:cell withIndex:bottomNum<cellNum?bottomNum+1:bottomNum];
                    
                    [self changeCell:cell WithFrame:CGRectMake(0, bottomY, _cellWidth, _cellHeight) andData:(KATTableCellData *)[_dataArray get:bottomData+1]];//更新被删除的cell，让它变成最底下的数据
                    
                    if(cellNum>(bottomNum<cellNum?bottomNum+1:bottomNum) || bottomNum==0)//如果0号位置需要移动
                    {
                        [_cellArray forwardByStep:1];//cell数组向前移动一位
                    }
                    
//                    NSLog(@"by=%.1f",bottomY);
                }
                else if(_displayOffset>0)
                {
                    [_cellArray deleteMember:cell];
                    [_cellArray put:cell withIndex:topNum>cellNum?topNum-1:topNum];
                    
                    [self changeCell:cell WithFrame:CGRectMake(0, topY-_cellHeight-_cellMarginInner, _cellWidth, _cellHeight) andData:(KATTableCellData *)[_dataArray get:topData>0?topData-1:0]];//更新被删除的cell，让它变成最上的数据
                    
                    _displayOffset--;
                    
                    if(topNum<=cellNum)
                    {
                        [_cellArray forwardByStep:1];//cell数组向前移动一位
                    }
                    
                }
                else if(_displayOffset<=0)
                {
                    [_cellArray deleteMember:cell];
                    [_cellArray put:cell withIndex:bottomNum<cellNum?bottomNum+1:bottomNum];
                    
                    cell.frame=CGRectMake(cell.frame.origin.x, bottomY, cell.bounds.size.width, cell.bounds.size.height);
                }
                
                
                //更新所有的cell的num，将之与数组中的顺序对应
                for(int i=0;i<_cellArray.length;i++)
                {
                    KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                    
                    [self updateCell:c withNum:i];
//                    NSLog(@"++++++ %i: title=%@ y=%.1f",i,c.data.title,c.frame.origin.y);
                }
                
//                NSLog(@"%@",_cellArray);
                
                //滚动控件大小重新计算
                [UIView animateWithDuration:_cellRemoveTime*0.5 animations:^
                {
                    //设置滚动视图内容大小
                    if(_startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom+_bottomInsertHeight > self.scrollView.bounds.size.height)
                    {
                        self.scrollView.contentSize=CGSizeMake(self.scrollView.bounds.size.width, _startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom+_bottomInsertHeight);
                    }
                    else
                    {
                        self.scrollView.contentSize=CGSizeMake(self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
                    }
                    
//                    NSLog(@"contentSize=%.1f",_scrollView.contentSize.height);
                    
                    //加载上推控件
                    if(_hasPushFooter)
                    {
                        _pushFooter.frame=CGRectMake(0, self.scrollView.contentSize.height, _cellWidth, _pushFooterHeight);
                    }
                }
                completion:^(BOOL finished)
                {
                    if(_eventDelegate && [_eventDelegate respondsToSelector:@selector(tableView:didRemoveCell:)])
                    {
                        [_eventDelegate tableView:self didRemoveCell:cell];
                    }
                }];
                
                //恢复滑动
                _scrollView.scrollEnabled=YES;
                
                //恢复状态
                _state=TABLE_STATE_READY;
                
            }];
            
        }];
    }
}


//在列表头部添加cell
- (void)addCellOnHeadWithData:(KATTableCellData *)data
{
    if(_state==TABLE_STATE_READY && data)
    {
        //停止滑动
        _scrollView.scrollEnabled=NO;
        
        //滚动到列表头
        [_scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
        
        //改变状态
        _state=TABLE_STATE_ADD;
        
        
        //动画
        [UIView animateWithDuration:_cellRemoveTime*0.5 animations:^//cell全部下移
         {
             for(int i=0;i<_cellArray.length && i<_dataArray.length;i++)
             {
                 KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                 
                 c.frame=CGRectMake(0, c.frame.origin.y+c.bounds.size.height, c.bounds.size.width, c.bounds.size.height);

             }
         }
         completion:^(BOOL finished)
         {
             //最下面一个cell准备移动到列表头
             KATTableCell *cell=(KATTableCell *)[_cellArray get:(_dataArray.length>=_cellsDisplayMax?_cellsDisplayMax-1:_dataArray.length)];
             cell.midLayer.frame=CGRectMake(0, 0, cell.midLayer.bounds.size.width, cell.midLayer.bounds.size.height);
             cell.frame=CGRectMake(cell.bounds.size.width, 0, cell.bounds.size.width, cell.bounds.size.height);
             cell.alpha=0.4f;
             cell.state=TABLE_CELL_STATE_READY;
             cell.data=data;
             
             if(_dataArray.length<_cellsDisplayMax)
             {
                 [_scrollView addSubview:cell];
             }
             
             [self changeCell:cell WithFrame:CGRectMake(cell.bounds.size.width, _startPositionY, cell.bounds.size.width, cell.bounds.size.height) andData:data];
             
             //插入data数据
             [_dataArray put:data withIndex:0];
             
             //更新data数组
             [self updateCellDataNum];
             
             //让底部的cell移动到顶部
             [_cellArray deleteMember:cell];
             [_cellArray put:cell withIndex:0];
             
             
             [UIView animateWithDuration:_cellRemoveTime animations:^//添加的cell左移
              {
                  cell.frame=CGRectMake(0, cell.frame.origin.y, cell.bounds.size.width, cell.bounds.size.height);
                  cell.alpha=1.0f;
              }
              completion:^(BOOL finished)
              {
                  //更新所有的cell的num，将之与数组中的顺序对应
                  for(int i=0;i<_cellArray.length;i++)
                  {
                      KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                      
                      [self updateCell:c withNum:i];
                  }
                  
                  
                  //滚动控件大小重新计算
                  [UIView animateWithDuration:_cellRemoveTime*0.5 animations:^
                   {
                       //设置滚动视图内容大小
                       if(_startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom+_bottomInsertHeight > self.scrollView.bounds.size.height)
                       {
                           self.scrollView.contentSize=CGSizeMake(self.scrollView.bounds.size.width, _startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom+_bottomInsertHeight);
                       }
                       else
                       {
                           self.scrollView.contentSize=CGSizeMake(self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
                       }
                       
                       //加载上推控件
                       if(_hasPushFooter)
                       {
                           _pushFooter.frame=CGRectMake(0, self.scrollView.contentSize.height, _cellWidth, _pushFooterHeight);
                       }
                   }];
                  
                  //恢复滑动
                  _scrollView.scrollEnabled=YES;
                  
                  if(_eventDelegate && [_eventDelegate respondsToSelector:@selector(tableView:didAddCell:)])
                  {
                      [_eventDelegate tableView:self didAddCell:cell];
                  }
                  
                  //恢复状态
                  _state=TABLE_STATE_READY;
              }];
             
         }];
    }
}


//在列表尾部添加cell
- (void)addCellOnTailWithData:(KATTableCellData *)data
{
    if(_state==TABLE_STATE_READY && data)
    {
        //停止滑动
        _scrollView.scrollEnabled=NO;
        
        
        //滚动到列表尾
        [_scrollView setContentOffset:CGPointMake(0, _scrollView.contentSize.height-_scrollView.bounds.size.height) animated:NO];
        
        //改变状态
        _state=TABLE_STATE_ADD;
        
        //设置滚动视图内容大小
        if(_startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom+_bottomInsertHeight > self.scrollView.bounds.size.height)
        {
            self.scrollView.contentSize=CGSizeMake(self.scrollView.bounds.size.width, _startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*_dataArray.length+_cellMarginBottom+_bottomInsertHeight);
        }
        else
        {
            self.scrollView.contentSize=CGSizeMake(self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
        }
        
        //加载上推控件
        if(_hasPushFooter)
        {
            _pushFooter.frame=CGRectMake(0, self.scrollView.contentSize.height, _cellWidth, _pushFooterHeight);
        }
        
        //动画
        [UIView animateWithDuration:_cellRemoveTime*0.5 animations:^//再次滚动到末尾
        {
            [_scrollView setContentOffset:CGPointMake(0, _scrollView.contentSize.height-_scrollView.bounds.size.height)];
        }
        completion:^(BOOL finished)
        {
            //最上面一个cell准备移动到列表头
            KATTableCell *cell=(KATTableCell *)[_cellArray get:(_dataArray.length>=_cellsDisplayMax?_displayOffset%_cellsDisplayMax:_dataArray.length)];
            cell.midLayer.frame=CGRectMake(0, 0, cell.midLayer.bounds.size.width, cell.midLayer.bounds.size.height);
            cell.frame=CGRectMake(cell.bounds.size.width, _startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*(_dataArray.length), cell.bounds.size.width, cell.bounds.size.height);
            cell.alpha=0.4f;
            cell.state=TABLE_CELL_STATE_READY;
            cell.data=data;
             
//            NSLog(@"%i",_displayOffset);
            
            if(_dataArray.length<_cellsDisplayMax)
            {
                [_scrollView addSubview:cell];
            }
            else
            {
                _displayOffset++;
                
                //让顶部的cell移动到底部
                [_cellArray deleteMember:cell];
                [_cellArray put:cell withIndex:(_displayOffset%_cellsDisplayMax>0?_displayOffset%_cellsDisplayMax-1:_cellsDisplayMax-1)];
            }
             
            [self changeCell:cell WithFrame:CGRectMake(cell.bounds.size.width, _startPositionY+_cellMarginTop+(_cellHeight+_cellMarginInner)*(_dataArray.length), cell.bounds.size.width, cell.bounds.size.height) andData:data];
             
             
            [UIView animateWithDuration:_cellRemoveTime animations:^//添加的cell左移
            {
                cell.frame=CGRectMake(0, cell.frame.origin.y, cell.bounds.size.width, cell.bounds.size.height);
                cell.alpha=1.0f;
            }
            completion:^(BOOL finished)
            {
                //插入data数据
                [_dataArray put:data withIndex:_dataArray.length];
                
                //更新data数组
                [self updateCellDataNum];
                
                //更新所有的cell的num，将之与数组中的顺序对应
                for(int i=0;i<_cellArray.length;i++)
                {
                    KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                    
                    [self updateCell:c withNum:i];
                }
                
                //恢复滑动
                _scrollView.scrollEnabled=YES;
                
                if(_eventDelegate && [_eventDelegate respondsToSelector:@selector(tableView:didAddCell:)])
                {
                    [_eventDelegate tableView:self didAddCell:cell];
                }
                
                //恢复状态
                _state=TABLE_STATE_READY;
            }];
            
        }];
    }
}


//添加cell到指定位置
- (void)addCellWithData:(KATTableCellData *)data andIndex:(int)index
{
    //待实现
}




//cell位置上移
- (void)moveUpWithCell:(KATTableCell *)cell
{
    if(_state==TABLE_STATE_READY && cell.data.num>0 && cell)
    {
        //改变状态
        _state=TABLE_STATE_MOVE;
        
        //禁止滚动
        _scrollView.scrollEnabled=NO;
        
        
        //如果需要上移的cell不在显示范围内，则设置offset
//        if(cell.frame.origin.y<_scrollView.contentOffset.y)
//        {
//            [_scrollView setContentOffset:CGPointMake(0, cell.frame.origin.y)];
//        }
        
        
        //将该cell置为最上层
        [_scrollView bringSubviewToFront:cell];
        
        
        //找到该cell需要交换的cell（相邻的上一个cell）
        KATTableCell *changeCell=(KATTableCell *)[_cellArray get:(cell.num>0?cell.num-1:_cellArray.length-1)];
        
        
        //需要交换的数组索引
        int cellIndex=cell.num;
        int dataIndex=cell.data.num;
        int changeCellIndex=changeCell.num;
        int changeDataIndex=changeCell.data.num;
        
        
        //交换data数组位置
        [_dataArray changePositionWithIndexA:dataIndex andIndexB:changeDataIndex];
        [self updateCellDataNum];
        
        
        //交换cell数组位置
        [_cellArray changePositionWithIndexA:cellIndex andIndexB:changeCellIndex];
        
        //更新所有的cell的num，将之与数组中的顺序对应
        for(int i=0;i<_cellArray.length;i++)
        {
            KATTableCell *c=(KATTableCell *)[_cellArray get:i];
            
            [self updateCell:c withNum:i];
        }
        
        
        //将cell设置为半透明
        cell.alpha=0.6f;
        changeCell.alpha=0.6f;
        
        
        //交换动画
        [UIView animateWithDuration:_cellRemoveTime*0.5 animations:^
         {
             //透明度恢复正常
             cell.alpha=1.0f;
             changeCell.alpha=1.0f;
             
             CGRect tmpFrame=cell.frame;
             
             cell.frame=changeCell.frame;
             changeCell.frame=tmpFrame;
         }
         completion:^(BOOL finished)
         {
             //恢复滚动
             _scrollView.scrollEnabled=YES;
             
             //恢复状态
             _state=TABLE_STATE_READY;
         }];
    }
}


//cell位置下移
- (void)moveDownWithCell:(KATTableCell *)cell
{
    if(_state==TABLE_STATE_READY && cell.data.num<_dataArray.length-1 && cell)
    {
        //改变状态
        _state=TABLE_STATE_MOVE;
        
        //禁止滚动
        _scrollView.scrollEnabled=NO;
        
        
        //将该cell置为最上层
        [_scrollView bringSubviewToFront:cell];
        
        
        //找到该cell需要交换的cell（相邻的下一个cell）
        KATTableCell *changeCell=(KATTableCell *)[_cellArray get:(cell.num<_cellArray.length-1?cell.num+1:0)];
        
        
        //需要交换的数组索引
        int cellIndex=cell.num;
        int dataIndex=cell.data.num;
        int changeCellIndex=changeCell.num;
        int changeDataIndex=changeCell.data.num;
        
        
        //交换data数组位置
        [_dataArray changePositionWithIndexA:dataIndex andIndexB:changeDataIndex];
        [self updateCellDataNum];
        
        
        //交换cell数组位置
        [_cellArray changePositionWithIndexA:cellIndex andIndexB:changeCellIndex];
        
        //更新所有的cell的num，将之与数组中的顺序对应
        for(int i=0;i<_cellArray.length;i++)
        {
            KATTableCell *c=(KATTableCell *)[_cellArray get:i];
            
            [self updateCell:c withNum:i];
        }
        
        
        //将cell设置为半透明
        cell.alpha=0.6f;
        changeCell.alpha=0.6f;
        
        
        //交换动画
        [UIView animateWithDuration:_cellRemoveTime*0.5 animations:^
         {
             //透明度恢复正常
             cell.alpha=1.0f;
             changeCell.alpha=1.0f;
             
             CGRect tmpFrame=cell.frame;
             
             cell.frame=changeCell.frame;
             changeCell.frame=tmpFrame;
         }
         completion:^(BOOL finished)
         {
             //恢复滚动
             _scrollView.scrollEnabled=YES;
             
             //恢复状态
             _state=TABLE_STATE_READY;
         }];
    }
}


//cell位置置顶
- (void)moveTopWithCell:(KATTableCell *)cell
{
    if(_state==TABLE_STATE_READY && cell.data.num>0 && cell)
    {
        //改变状态
        _state=TABLE_STATE_MOVE;
        
        //禁止滚动
        _scrollView.scrollEnabled=NO;

        
        //将该cell置为最上层
        [_scrollView bringSubviewToFront:cell];
        
        
        //找到该cell需要交换的cell（相邻的上一个cell）
        KATTableCell *changeCell=(KATTableCell *)[_cellArray get:(_displayOffset>0?_displayOffset%_cellArray.length:0)];
        CGRect topFrame=changeCell.frame;
        
        //移动data数组位置
        [_dataArray deleteMember:cell.data];
        [_dataArray put:cell.data withIndex:0];
        [self updateCellDataNum];
        
        
        //移动cell数组位置（分情况）
        if(_displayOffset>0)//移动到当前最上面的显示cell
        {
            [_cellArray deleteMember:cell];
            
            if(cell.num<changeCell.num)//若需要移动的cell的位置较交换位置的cell数组位置小，则删除时会使得交换位置的cell前移，所以需要位置－1
            {
                [_cellArray put:cell withIndex:changeCell.num>0?changeCell.num-1:_cellArray.length-1];
            }
            else
            {
                [_cellArray put:cell withIndex:changeCell.num];
            }
            
            [self changeCell:cell WithFrame:cell.frame andData:[_dataArray get:_displayOffset]];
            
            if(cell.num<changeCell.num)
            {
                [_cellArray backwardByStep:1];
            }
            
        }
        else//移动到首个显示cell
        {
            [_cellArray deleteMember:cell];
            [_cellArray put:cell withIndex:0];
        }
        
        //更新所有的cell的num，将之与数组中的顺序对应
        for(int i=0;i<_cellArray.length;i++)
        {
            KATTableCell *c=(KATTableCell *)[_cellArray get:i];
            
            [self updateCell:c withNum:i];
        }
        
        
        //将cell设置为半透明
        cell.alpha=0.6f;
        
        //交换动画
        [UIView animateWithDuration:_cellRemoveTime*0.5 animations:^
         {
             //所有在cell之上的cell下移
             for(int i=0;i<_cellArray.length;i++)
             {
                 KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                 
                 if(c.frame.origin.y < cell.frame.origin.y)
                 {
                     c.frame=CGRectMake(c.frame.origin.x, c.frame.origin.y+(_cellHeight+_cellMarginInner), c.bounds.size.width, c.bounds.size.height);
                 }
             }
             
             //透明度恢复正常
             cell.alpha=1.0f;
             
             cell.frame=topFrame;
         }
         completion:^(BOOL finished)
         {
             //恢复滚动
             _scrollView.scrollEnabled=YES;
             
             //恢复状态
             _state=TABLE_STATE_READY;
         }];
    }
}


//cell位置置底
- (void)moveBottomWithCell:(KATTableCell *)cell
{
    if(_state==TABLE_STATE_READY && cell.data.num<_dataArray.length-1 && cell)
    {
        //改变状态
        _state=TABLE_STATE_MOVE;
        
        //禁止滚动
        _scrollView.scrollEnabled=NO;
        
        
        //将该cell置为最上层
        [_scrollView bringSubviewToFront:cell];
        
        
        //找到该cell需要交换的cell（相邻的上一个cell）
        KATTableCell *changeCell=(KATTableCell *)[_cellArray get:(_cellsDisplayMax<_dataArray.length?(_displayOffset%_cellArray.length==0?_cellArray.length-1:_displayOffset%_cellArray.length-1):_dataArray.length-1)];
        CGRect bottomFrame=changeCell.frame;
        
        
        //移动data数组位置
        [_dataArray deleteMember:cell.data];
        [_dataArray put:cell.data withIndex:_dataArray.length];
        [self updateCellDataNum];
        
        
        //移动cell数组位置（分情况）
        if(_cellsDisplayMax<_dataArray.length)//移动到当前最下面的显示cell
        {
            [_cellArray deleteMember:cell];
            
            if(cell.num>changeCell.num)//若需要移动的cell的位置较交换位置的cell数组位置小，则删除时会使得交换位置的cell前移，所以需要位置－1
            {
                [_cellArray put:cell withIndex:changeCell.num<_cellArray.length-1?changeCell.num+1:0];
            }
            else
            {
                [_cellArray put:cell withIndex:changeCell.num];
            }
            
            [self changeCell:cell WithFrame:cell.frame andData:[_dataArray get:_displayOffset+_cellsDisplayMax-1]];
            
            if(cell.num>changeCell.num)
            {
                [_cellArray forwardByStep:1];
            }
        }
        else//移动到最后一个显示cell
        {
            [_cellArray deleteMember:cell];
            [_cellArray put:cell withIndex:_dataArray.length-1];
        }
        
        //更新所有的cell的num，将之与数组中的顺序对应
        for(int i=0;i<_cellArray.length;i++)
        {
            KATTableCell *c=(KATTableCell *)[_cellArray get:i];
            
            [self updateCell:c withNum:i];
        }
        
        
        //将cell设置为半透明
        cell.alpha=0.6f;
        
        //交换动画
        [UIView animateWithDuration:_cellRemoveTime*0.5 animations:^
         {
             //所有在cell之上的cell上移
             for(int i=0;i<_cellArray.length;i++)
             {
                 KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                 
                 if(c.frame.origin.y > cell.frame.origin.y)
                 {
                     c.frame=CGRectMake(c.frame.origin.x, c.frame.origin.y-(_cellHeight+_cellMarginInner), c.bounds.size.width, c.bounds.size.height);
                 }
             }
             
             //透明度恢复正常
             cell.alpha=1.0f;
             
             cell.frame=bottomFrame;
         }
         completion:^(BOOL finished)
         {
             //恢复滚动
             _scrollView.scrollEnabled=YES;
             
             //恢复状态
             _state=TABLE_STATE_READY;
         }];
    }
}


//修改cell
- (void)updateCellWithData:(KATTableCellData *)data
{
    //待实现
}


//改变点击色（只针对当前Cell，重用无效）
- (void)changeTapedColorWithCell:(KATTableCell *)cell
{
    cell.isTapedColor=YES;
    
    //改变背景颜色
    cell.midLayer.backgroundColor=_tapedBgColor;
    
    //徽标颜色
    if(_hasBadge && cell.badge && cell.data.hasBadge && cell.data.badge)
    {
        cell.badge.backgroundColor=[UIColor clearColor];
        cell.badge.textColor=_tapedTextColor;
        
        if(_hasBadgeBorder)
        {
            cell.badge.layer.borderWidth=0;
        }
    }
    
    //button颜色
    if(_hasButton1 && cell.button1)
    {
        cell.button1.color=_tapedButtonColor;
    }
    
    if(_hasButton2 && cell.button2)
    {
        cell.button2.color=_tapedButtonColor;
    }
    
    if(_hasButton3 && cell.button3)
    {
        cell.button3.color=_tapedButtonColor;
    }
    
    if(_hasSpButton && cell.spButton && cell.data.hasSpButton)
    {
        cell.spButton.color=_tapedButtonColor;
    }
    
    //文本颜色
    if(_hasTitle && cell.title)
    {
        cell.title.textColor=_tapedTextColor;
    }
    
    if(_hasContent && cell.content)
    {
        cell.content.textColor=_tapedTextColor;
    }
    
    if(_hasLabel1 && cell.label1)
    {
        cell.label1.textColor=_tapedTextColor;
    }
    
    if(_hasLabel2 && cell.label2)
    {
        cell.label2.textColor=_tapedTextColor;
    }
    
    if(_hasLabel3 && cell.label3)
    {
        cell.label3.textColor=_tapedTextColor;
    }
    
    if(_hasLabel4 && cell.label4)
    {
        cell.label4.textColor=_tapedTextColor;
    }
    
    if(_hasLabel5 && cell.label5)
    {
        cell.label5.textColor=_tapedTextColor;
    }
}


//改变回原色(只针对Cell，重用无效)
- (void)changeOriginalColorWithCell:(KATTableCell *)cell
{
    cell.isTapedColor=NO;
    
    //改变背景颜色
    cell.midLayer.backgroundColor=_midBgColor;
    
    //徽标颜色
    if(_hasBadge && cell.badge && cell.data.hasBadge && cell.data.badge)
    {
        cell.badge.backgroundColor=_badgeBgColor;
        cell.badge.textColor=_badgeTextColor;
        
        if(_hasBadgeBorder)
        {
            cell.badge.layer.borderWidth=_badgeBorderWidth;
        }
    }
    
    //button颜色
    if(_hasButton1 && cell.button1)
    {
        cell.button1.color=_button1Color;
    }
    
    if(_hasButton2 && cell.button2)
    {
        cell.button2.color=_button2Color;
    }
    
    if(_hasButton3 && cell.button3)
    {
        cell.button3.color=_button3Color;
    }
    
    if(_hasSpButton && cell.spButton && cell.data.hasSpButton)
    {
        cell.spButton.color=cell.data.spButtonColor;
    }
    
    
    //文本颜色
    if(_hasTitle && cell.title)
    {
        cell.title.textColor=_titleColor;
        
        if(cell.data.hasTitleColor && cell.data.titleColor)
        {
            cell.title.textColor=cell.data.titleColor;
        }
    }
    
    if(_hasContent && cell.content)
    {
        cell.content.textColor=_contentColor;
        
        if(cell.data.hasContentColor && cell.data.contentColor)
        {
            cell.content.textColor=cell.data.contentColor;
        }
    }
    
    if(_hasLabel1 && cell.label1)
    {
        cell.label1.textColor=_label1Color;
        
        if(cell.data.hasLabel1Color && cell.data.label1Color)
        {
            cell.label1.textColor=cell.data.label1Color;
        }
    }
    
    if(_hasLabel2 && cell.label2)
    {
        cell.label2.textColor=_label2Color;
        
        if(cell.data.hasLabel2Color && cell.data.label2Color)
        {
            cell.label2.textColor=cell.data.label2Color;
        }
    }
    
    if(_hasLabel3 && cell.label3)
    {
        cell.label3.textColor=_label3Color;
        
        if(cell.data.hasLabel3Color && cell.data.label3Color)
        {
            cell.label3.textColor=cell.data.label3Color;
        }
    }
    
    if(_hasLabel4 && cell.label4)
    {
        cell.label4.textColor=_label4Color;
        
        if(cell.data.hasLabel4Color && cell.data.label4Color)
        {
            cell.label4.textColor=cell.data.label4Color;
        }
    }
    
    if(_hasLabel5 && cell.label5)
    {
        cell.label5.textColor=_label5Color;
        
        if(cell.data.hasLabel5Color && cell.data.label5Color)
        {
            cell.label5.textColor=cell.data.label5Color;
        }
    }
}


//通过index排列cells
- (void)sortCellsByIndexAndOrder:(BOOL)asc
{
    if(_state==TABLE_STATE_READY && _dataArray.length>1)
    {
        //改变状态
        _state=TABLE_STATE_MOVE;
        
        //禁止滚动
        _scrollView.scrollEnabled=NO;
        
        //停止滚动
        _scrollView.decelerationRate=0.0;
        
        
        //排序
        
        //变量
        KATTreeMap *tree=[KATTreeMap treeMap];//二叉树容器
        
        //插入二叉树
        for(int i=0;i<_dataArray.length;i++)
        {
            KATTableCellData *data=(KATTableCellData *)[_dataArray get:i];
            
            [tree putWithKey:[NSString stringWithFormat:@"%lli_%i",500000000000L+data.index,1000000+i] andValue:data];
        }
        
        //将二叉树转换成数组
        KATArray *array=[tree allValues];
        
        if(!asc)//反序排列
        {
            [array reverse];
        }
        
        
        //清空data数组
        [_dataArray clear];
        
        //将排序后的数组存入data数组
        [_dataArray putArray:array withIndex:0];
        
        //更新data数组的num
        [self updateCellDataNum];
        
        
        //左右滑动cell恢复
        [self allCellsBackToPositionWithAnimated:NO];
 
        
        //动画
        [UIView animateWithDuration:_cellRemoveTime animations:^
        {
            //所有cell左右交叉移动
            for(int i=0;i<_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                if(c.num%2==0)
                {
                    c.frame=CGRectMake(-c.bounds.size.width, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
                else
                {
                    c.frame=CGRectMake(c.bounds.size.width, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
            }
            
        }
        completion:^(BOOL finished)
        {
            //更新cell数据内容
            for(int i=_displayOffset%_cellArray.length;i<_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                [self changeCell:c WithFrame:c.frame andData:[_dataArray get:_displayOffset+i-_displayOffset%_cellArray.length]];
            }
            
            for(int i=0;i<_displayOffset%_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                [self changeCell:c WithFrame:c.frame andData:[_dataArray get:_displayOffset+_cellArray.length-_displayOffset%_cellArray.length+i]];
            }
            
            [UIView animateWithDuration:_cellRemoveTime animations:^
            {
                //所有cell回归原位
                for(int i=0;i<_cellArray.length;i++)
                {
                    KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                    
                    c.frame=CGRectMake(0, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
            }
            completion:^(BOOL finished)
            {
                //恢复
                _scrollView.decelerationRate=1.0;
                
                //恢复滚动
                _scrollView.scrollEnabled=YES;
                
                //恢复状态
                _state=TABLE_STATE_READY;
            }];
             
        }];
    }
}



//通过tag排列cells
- (void)sortCellsByTagAndOrder:(BOOL)asc
{
    if(_state==TABLE_STATE_READY && _dataArray.length>1)
    {
        //改变状态
        _state=TABLE_STATE_MOVE;
        
        //禁止滚动
        _scrollView.scrollEnabled=NO;
        
        //停止滚动
        _scrollView.decelerationRate=0.0;
        
        
        //排序
        
        //变量
        KATTreeMap *tree=[KATTreeMap treeMap];//二叉树容器
        
        //插入二叉树
        for(int i=0;i<_dataArray.length;i++)
        {
            KATTableCellData *data=(KATTableCellData *)[_dataArray get:i];
            
            [tree putWithKey:[NSString stringWithFormat:@"%lli_%i",500000000000L+data.tag,1000000+i] andValue:data];
        }
        
        //将二叉树转换成数组
        KATArray *array=[tree allValues];
        
        if(!asc)//反序排列
        {
            [array reverse];
        }
        
        
        //清空data数组
        [_dataArray clear];
        
        //将排序后的数组存入data数组
        [_dataArray putArray:array withIndex:0];
        
        //更新data数组的num
        [self updateCellDataNum];
        
        
        //左右滑动cell恢复
        [self allCellsBackToPositionWithAnimated:NO];
        
        
        //动画
        [UIView animateWithDuration:_cellRemoveTime animations:^
        {
            //所有cell左右交叉移动
            for(int i=0;i<_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                if(c.num%2==0)
                {
                    c.frame=CGRectMake(-c.bounds.size.width, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
                else
                {
                    c.frame=CGRectMake(c.bounds.size.width, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
            }
            
        }
        completion:^(BOOL finished)
        {
            //更新cell数据内容
            for(int i=_displayOffset%_cellArray.length;i<_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                [self changeCell:c WithFrame:c.frame andData:[_dataArray get:_displayOffset+i-_displayOffset%_cellArray.length]];
            }
            
            for(int i=0;i<_displayOffset%_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
            
                [self changeCell:c WithFrame:c.frame andData:[_dataArray get:_displayOffset+_cellArray.length-_displayOffset%_cellArray.length+i]];
            }
             
            [UIView animateWithDuration:_cellRemoveTime animations:^
            {
                //所有cell回归原位
                for(int i=0;i<_cellArray.length;i++)
                {
                    KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                    
                    c.frame=CGRectMake(0, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
            }
            completion:^(BOOL finished)
            {
                //恢复
                _scrollView.decelerationRate=1.0;
                
                //恢复滚动
                _scrollView.scrollEnabled=YES;
                
                //恢复状态
                _state=TABLE_STATE_READY;
            }];
            
        }];
    }
}


//通过type排列cells
- (void)sortCellsByTypeAndOrder:(BOOL)asc
{
    if(_state==TABLE_STATE_READY && _dataArray.length>1)
    {
        //改变状态
        _state=TABLE_STATE_MOVE;
        
        //禁止滚动
        _scrollView.scrollEnabled=NO;
        
        //停止滚动
        _scrollView.decelerationRate=0.0;
        
        
        //排序
        
        //变量
        KATTreeMap *tree=[KATTreeMap treeMap];//二叉树容器
        
        //插入二叉树
        for(int i=0;i<_dataArray.length;i++)
        {
            KATTableCellData *data=(KATTableCellData *)[_dataArray get:i];
            
            [tree putWithKey:[NSString stringWithFormat:@"%i_%i",500000000+data.type,1000000+i] andValue:data];
        }
        
        //将二叉树转换成数组
        KATArray *array=[tree allValues];
        
        if(!asc)//反序排列
        {
            [array reverse];
        }
        
        
        //清空data数组
        [_dataArray clear];
        
        //将排序后的数组存入data数组
        [_dataArray putArray:array withIndex:0];
        
        //更新data数组的num
        [self updateCellDataNum];
        
        
        //左右滑动cell恢复
        [self allCellsBackToPositionWithAnimated:NO];
        
        
        //动画
        [UIView animateWithDuration:_cellRemoveTime animations:^
        {
            //所有cell左右交叉移动
            for(int i=0;i<_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                if(c.num%2==0)
                {
                    c.frame=CGRectMake(-c.bounds.size.width, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
                else
                {
                    c.frame=CGRectMake(c.bounds.size.width, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
            }
            
        }
        completion:^(BOOL finished)
        {
            //更新cell数据内容
            for(int i=_displayOffset%_cellArray.length;i<_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                [self changeCell:c WithFrame:c.frame andData:[_dataArray get:_displayOffset+i-_displayOffset%_cellArray.length]];
            }
            
            for(int i=0;i<_displayOffset%_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                [self changeCell:c WithFrame:c.frame andData:[_dataArray get:_displayOffset+_cellArray.length-_displayOffset%_cellArray.length+i]];
            }
            
            [UIView animateWithDuration:_cellRemoveTime animations:^
            {
                //所有cell回归原位
                for(int i=0;i<_cellArray.length;i++)
                {
                    KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                    
                    c.frame=CGRectMake(0, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
            }
            completion:^(BOOL finished)
            {
                //恢复
                _scrollView.decelerationRate=1.0;
                
                //恢复滚动
                _scrollView.scrollEnabled=YES;
                
                //恢复状态
                _state=TABLE_STATE_READY;
            }];
             
        }];
    }
}


//通过value排列cells
- (void)sortCellsByValueAndOrder:(BOOL)asc
{
    if(_state==TABLE_STATE_READY && _dataArray.length>1)
    {
        //改变状态
        _state=TABLE_STATE_MOVE;
        
        //禁止滚动
        _scrollView.scrollEnabled=NO;
        
        //停止滚动
        _scrollView.decelerationRate=0.0;
        
        
        //排序
        
        //变量
        KATTreeMap *tree=[KATTreeMap treeMap];//二叉树容器
        
        //插入二叉树
        for(int i=0;i<_dataArray.length;i++)
        {
            KATTableCellData *data=(KATTableCellData *)[_dataArray get:i];
            
            [tree putWithKey:[NSString stringWithFormat:@"%.9lf_%i",500000000.0+data.value,1000000+i] andValue:data];
        }
        
        //将二叉树转换成数组
        KATArray *array=[tree allValues];
        
        if(!asc)//反序排列
        {
            [array reverse];
        }
        
        
        //清空data数组
        [_dataArray clear];
        
        //将排序后的数组存入data数组
        [_dataArray putArray:array withIndex:0];
        
        //更新data数组的num
        [self updateCellDataNum];
        
        
        //左右滑动cell恢复
        [self allCellsBackToPositionWithAnimated:NO];
        
        
        //动画
        [UIView animateWithDuration:_cellRemoveTime animations:^
        {
            //所有cell左右交叉移动
            for(int i=0;i<_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                if(c.num%2==0)
                {
                    c.frame=CGRectMake(-c.bounds.size.width, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
                else
                {
                    c.frame=CGRectMake(c.bounds.size.width, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
            }
            
        }
        completion:^(BOOL finished)
        {
            //更新cell数据内容
            for(int i=_displayOffset%_cellArray.length;i<_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                [self changeCell:c WithFrame:c.frame andData:[_dataArray get:_displayOffset+i-_displayOffset%_cellArray.length]];
            }
            
            for(int i=0;i<_displayOffset%_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                [self changeCell:c WithFrame:c.frame andData:[_dataArray get:_displayOffset+_cellArray.length-_displayOffset%_cellArray.length+i]];
            }
        
            [UIView animateWithDuration:_cellRemoveTime animations:^
            {
                //所有cell回归原位
                for(int i=0;i<_cellArray.length;i++)
                {
                    KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                    
                    c.frame=CGRectMake(0, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
            }
            completion:^(BOOL finished)
            {
                //恢复
                _scrollView.decelerationRate=1.0;
                
                //恢复滚动
                _scrollView.scrollEnabled=YES;
                
                //恢复状态
                _state=TABLE_STATE_READY;
            }];
            
        }];
    }
}


//通过message排列cells
- (void)sortCellsByMessageAndOrder:(BOOL)asc
{
    if(_state==TABLE_STATE_READY && _dataArray.length>1)
    {
        //改变状态
        _state=TABLE_STATE_MOVE;
        
        //禁止滚动
        _scrollView.scrollEnabled=NO;
        
        //停止滚动
        _scrollView.decelerationRate=0.0;
        
        
        //排序
        
        //变量
        KATTreeMap *tree=[KATTreeMap treeMap];//二叉树容器
        
        //插入二叉树
        for(int i=0;i<_dataArray.length;i++)
        {
            KATTableCellData *data=(KATTableCellData *)[_dataArray get:i];
            
            [tree putWithKey:[NSString stringWithFormat:@"%@_%i",data.message,1000000+i] andValue:data];
        }
        
        //将二叉树转换成数组
        KATArray *array=[tree allValues];
        
        if(!asc)//反序排列
        {
            [array reverse];
        }
        
        
        //清空data数组
        [_dataArray clear];
        
        //将排序后的数组存入data数组
        [_dataArray putArray:array withIndex:0];
        
        //更新data数组的num
        [self updateCellDataNum];
        
        
        //左右滑动cell恢复
        [self allCellsBackToPositionWithAnimated:NO];
        
        
        //动画
        [UIView animateWithDuration:_cellRemoveTime animations:^
        {
            //所有cell左右交叉移动
            for(int i=0;i<_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                if(c.num%2==0)
                {
                    c.frame=CGRectMake(-c.bounds.size.width, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
                else
                {
                    c.frame=CGRectMake(c.bounds.size.width, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
            }
            
        }
        completion:^(BOOL finished)
        {
            //更新cell数据内容
            for(int i=_displayOffset%_cellArray.length;i<_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                [self changeCell:c WithFrame:c.frame andData:[_dataArray get:_displayOffset+i-_displayOffset%_cellArray.length]];
            }
            
            for(int i=0;i<_displayOffset%_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                [self changeCell:c WithFrame:c.frame andData:[_dataArray get:_displayOffset+_cellArray.length-_displayOffset%_cellArray.length+i]];
            }
            
            [UIView animateWithDuration:_cellRemoveTime animations:^
            {
                //所有cell回归原位
                for(int i=0;i<_cellArray.length;i++)
                {
                    KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                    
                    c.frame=CGRectMake(0, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
            }
            completion:^(BOOL finished)
            {
                //恢复
                _scrollView.decelerationRate=1.0;
                
                //恢复滚动
                _scrollView.scrollEnabled=YES;
                
                //恢复状态
                _state=TABLE_STATE_READY;
            }];
            
        }];
    }
}


//通过title排列cells
- (void)sortCellsByTitleAndOrder:(BOOL)asc
{
    if(_state==TABLE_STATE_READY && _dataArray.length>1)
    {
        //改变状态
        _state=TABLE_STATE_MOVE;
        
        //禁止滚动
        _scrollView.scrollEnabled=NO;
        
        //停止滚动
        _scrollView.decelerationRate=0.0;
        
        
        //排序
        
        //变量
        KATTreeMap *tree=[KATTreeMap treeMap];//二叉树容器
        
        //插入二叉树
        for(int i=0;i<_dataArray.length;i++)
        {
            KATTableCellData *data=(KATTableCellData *)[_dataArray get:i];
            
            [tree putWithKey:[NSString stringWithFormat:@"%@_%i",data.title,1000000+i] andValue:data];
        }
        
        //将二叉树转换成数组
        KATArray *array=[tree allValues];
        
        if(!asc)//反序排列
        {
            [array reverse];
        }
        
        
        //清空data数组
        [_dataArray clear];
        
        //将排序后的数组存入data数组
        [_dataArray putArray:array withIndex:0];
        
        //更新data数组的num
        [self updateCellDataNum];
        
        
        //左右滑动cell恢复
        [self allCellsBackToPositionWithAnimated:NO];
        
        
        //动画
        [UIView animateWithDuration:_cellRemoveTime animations:^
        {
            //所有cell左右交叉移动
            for(int i=0;i<_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                if(c.num%2==0)
                {
                    c.frame=CGRectMake(-c.bounds.size.width, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
                else
                {
                    c.frame=CGRectMake(c.bounds.size.width, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
            }
            
        }
        completion:^(BOOL finished)
        {
            //更新cell数据内容
            for(int i=_displayOffset%_cellArray.length;i<_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                [self changeCell:c WithFrame:c.frame andData:[_dataArray get:_displayOffset+i-_displayOffset%_cellArray.length]];
            }
            
            for(int i=0;i<_displayOffset%_cellArray.length;i++)
            {
                KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                
                [self changeCell:c WithFrame:c.frame andData:[_dataArray get:_displayOffset+_cellArray.length-_displayOffset%_cellArray.length+i]];
            }
            
            [UIView animateWithDuration:_cellRemoveTime animations:^
            {
                //所有cell回归原位
                for(int i=0;i<_cellArray.length;i++)
                {
                    KATTableCell *c=(KATTableCell *)[_cellArray get:i];
                    
                    c.frame=CGRectMake(0, c.frame.origin.y, c.bounds.size.width, c.bounds.size.height);
                }
            }
            completion:^(BOOL finished)
            {
                //恢复
                _scrollView.decelerationRate=1.0;
                
                //恢复滚动
                _scrollView.scrollEnabled=YES;
                
                //恢复状态
                _state=TABLE_STATE_READY;
            }];
             
        }];
    }
}


//隐藏键盘
- (void)hideKeyboard
{
    if(_hasText)
    {
        for(int i=0;i<_cellArray.length;i++)
        {
            KATTableCell *cell=(KATTableCell *)[_cellArray get:i];
            
            if(cell.text)
            {
                [cell.text resignFirstResponder];
            }
        }
    }
}


//获取点击的cell
- (KATTableCell *)getTapedCell
{
    if(_tapedCellNum>=0 && _tapedCellNum<_cellArray.length)
    {
        return (KATTableCell *)[_cellArray get:_tapedCellNum];
    }
    
    return nil;
}


#pragma mark - 事件处理

//cell点击事件
- (void)cellTap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    
    KATTableCell *cell=(KATTableCell *)[_cellArray get:(int)recognizer.view.tag];
    
    //变色处理
    if(cell.state==TABLE_CELL_STATE_READY && _isTapToChangeFaceLayerColor)
    {
        UIView *faceLayer=cell.faceLayer;
        UIColor *tmpColor=faceLayer.backgroundColor;
        
        [UIView animateWithDuration:_tapChangeColorTime*0.5 animations:^
        {
            faceLayer.backgroundColor=_tapedFaceLayerColor;
        }
        completion:^(BOOL finished)
        {
            [UIView animateWithDuration:_tapChangeColorTime*0.5 animations:^
            {
                faceLayer.backgroundColor=tmpColor;
            }
            completion:^(BOOL finished)
            {
                faceLayer.backgroundColor=tmpColor;
            }];
        }];
    }
    
    if(cell.state==TABLE_CELL_STATE_READY && _hasCellTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCell:)])
    {
        [_eventDelegate tableView:self didTapCell:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
    
    //背景点击处理
    [self backgroundTap:recognizer];

}


- (void)cellLongPress:(UILongPressGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    //变色处理
    KATTableCell *cell=(KATTableCell *)[_cellArray get:(int)recognizer.view.tag];
    
    if(cell.state==TABLE_CELL_STATE_READY)
    {
        //变色处理
        if(_isTapToChangeFaceLayerColor)
        {
            KATTableCell *cell=(KATTableCell *)[_cellArray get:(int)recognizer.view.tag];
            UIView *faceLayer=cell.faceLayer;
            
            if(recognizer.state==UIGestureRecognizerStateEnded)
            {
                if(_hasFaceBgColor && cell.data.hasFaceBgColor && cell.data.faceBgColor)
                {
                    faceLayer.backgroundColor=cell.data.faceBgColor;
                }
                else
                {
                    faceLayer.backgroundColor=_faceBgColor;
                }
            }
            else
            {
                faceLayer.backgroundColor=_tapedFaceLayerColor;
            }
        }
    }
    
    if(cell.state==TABLE_CELL_STATE_READY && _hasCellLongPressEvent && [_eventDelegate respondsToSelector:@selector(tableView:didPressCell:)] && recognizer.state==UIGestureRecognizerStateBegan)
    {
        [_eventDelegate tableView:self didPressCell:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
    
    //做背景点击处理
    [self backgroundTap:recognizer];
}


//table点击事件
- (void)tableTap
{
    [self allCellsBackToPositionWithAnimated:YES];
}


//表层点击事件
- (void)faceLayerTap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasFaceLayerTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellFaceLayer:)])
    {
        [_eventDelegate tableView:self didTapCellFaceLayer:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//中间层点击事件
- (void)midLayerTap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasMidLayerTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellMiddleLayer:)])
    {
        [_eventDelegate tableView:self didTapCellMiddleLayer:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//背景层点击事件
- (void)backLayerTap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasBackLayerTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellBackLayer:)])
    {
        [_eventDelegate tableView:self didTapCellBackLayer:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//图片点击事件
- (void)imageTap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasImageTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellImage:)])
    {
        [_eventDelegate tableView:self didTapCellImage:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//图片2点击事件
- (void)image2Tap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasImageTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellImage2:)])
    {
        [_eventDelegate tableView:self didTapCellImage2:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//图片3点击事件
- (void)image3Tap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasImageTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellImage3:)])
    {
        [_eventDelegate tableView:self didTapCellImage3:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//标题点击事件
- (void)titleTap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasTitleTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellTitle:)])
    {
        [_eventDelegate tableView:self didTapCellTitle:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//内容点击事件
- (void)contentTap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasContentTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellContent:)])
    {
        [_eventDelegate tableView:self didTapCellContent:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//富文本标题点击事件
- (void)richTitleTap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasRichTitleTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellRichTitle:)])
    {
        [_eventDelegate tableView:self didTapCellRichTitle:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//富文本内容点击事件
- (void)richContentTap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasRichContentTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellRichContent:)])
    {
        [_eventDelegate tableView:self didTapCellRichContent:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//富文本标签点击事件
- (void)richLabelTap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasRichLabelTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellRichLabel:)])
    {
        [_eventDelegate tableView:self didTapCellRichLabel:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//标签1点击事件
- (void)label1Tap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasLabel1TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellLabel1:)])
    {
        [_eventDelegate tableView:self didTapCellLabel1:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//标签2点击事件
- (void)label2Tap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasLabel2TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellLabel2:)])
    {
        [_eventDelegate tableView:self didTapCellLabel2:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//标签3点击事件
- (void)label3Tap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasLabel3TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellLabel3:)])
    {
        [_eventDelegate tableView:self didTapCellLabel3:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//标签4点击事件
- (void)label4Tap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasLabel4TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellLabel4:)])
    {
        [_eventDelegate tableView:self didTapCellLabel4:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//标签5点击事件
- (void)label5Tap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasLabel5TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellLabel5:)])
    {
        [_eventDelegate tableView:self didTapCellLabel5:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//按钮1点击事件
- (void)button1Tap:(KATButton *)button
{
    _tapedCellNum=(int)button.tag;
    
    if(_hasButton1TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellButton1:)])
    {
        [_eventDelegate tableView:self didTapCellButton1:(KATTableCell *)[_cellArray get:(int)button.tag]];
    }
}


//按钮2点击事件
- (void)button2Tap:(KATButton *)button
{
    _tapedCellNum=(int)button.tag;
    
    if(_hasButton2TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellButton2:)])
    {
        [_eventDelegate tableView:self didTapCellButton2:(KATTableCell *)[_cellArray get:(int)button.tag]];
    }
}


//按钮3点击事件
- (void)button3Tap:(KATButton *)button
{
    _tapedCellNum=(int)button.tag;
    
    if(_hasButton3TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellButton3:)])
    {
        [_eventDelegate tableView:self didTapCellButton3:(KATTableCell *)[_cellArray get:(int)button.tag]];
    }
}


//特殊按钮点击事件
- (void)spButtonTap:(KATButton *)button
{
    _tapedCellNum=(int)button.tag;
    
    if(_hasSpButtonTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellSPButton:)])
    {
        [_eventDelegate tableView:self didTapCellSPButton:(KATTableCell *)[_cellArray get:(int)button.tag]];
    }
}


//背景按钮1点击事件
- (void)backButton1Tap:(KATButton *)button
{
    _tapedCellNum=(int)button.tag;
    
    if(_hasBackButton1TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellBackButton1:)])
    {
        [_eventDelegate tableView:self didTapCellBackButton1:(KATTableCell *)[_cellArray get:(int)button.tag]];
    }
}


//背景按钮2点击事件
- (void)backButton2Tap:(KATButton *)button
{
    _tapedCellNum=(int)button.tag;
    
    if(_hasBackButton2TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellBackButton2:)])
    {
        [_eventDelegate tableView:self didTapCellBackButton2:(KATTableCell *)[_cellArray get:(int)button.tag]];
    }
}


//背景按钮3点击事件
- (void)backButton3Tap:(KATButton *)button
{
    _tapedCellNum=(int)button.tag;
    
    if(_hasBackButton3TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellBackButton3:)])
    {
        [_eventDelegate tableView:self didTapCellBackButton3:(KATTableCell *)[_cellArray get:(int)button.tag]];
    }
}


//背景按钮4点击事件
- (void)backButton4Tap:(KATButton *)button
{
    _tapedCellNum=(int)button.tag;
    
    if(_hasBackButton4TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellBackButton4:)])
    {
        [_eventDelegate tableView:self didTapCellBackButton4:(KATTableCell *)[_cellArray get:(int)button.tag]];
    }
}


//背景按钮5点击事件
- (void)backButton5Tap:(KATButton *)button
{
    _tapedCellNum=(int)button.tag;
    
    if(_hasBackButton5TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellBackButton5:)])
    {
        [_eventDelegate tableView:self didTapCellBackButton5:(KATTableCell *)[_cellArray get:(int)button.tag]];
    }
}


//背景按钮6点击事件
- (void)backButton6Tap:(KATButton *)button
{
    _tapedCellNum=(int)button.tag;
    
    if(_hasBackButton6TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellBackButton6:)])
    {
        [_eventDelegate tableView:self didTapCellBackButton6:(KATTableCell *)[_cellArray get:(int)button.tag]];
    }
}



//背景按钮7点击事件(与构造器的删除按钮对应)
- (void)backButton7Tap:(KATButton *)button
{
    _tapedCellNum=(int)button.tag;
    
    if(_builder && _builder.deleteEnabled)
    {
        [self removeCell:(KATTableCell *)[_cellArray get:(int)button.tag]];
    }
    else if(_hasBackButton7TapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellBackButton7:)])
    {
        [_eventDelegate tableView:self didTapCellBackButton7:(KATTableCell *)[_cellArray get:(int)button.tag]];
    }
}


//背景标签点击事件
- (void)backLabelTap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasBackLabelTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellBackLabel:)])
    {
        [_eventDelegate tableView:self didTapCellBackLabel:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}


//徽标点击事件
- (void)badgeTap:(UITapGestureRecognizer *)recognizer
{
    _tapedCellNum=(int)recognizer.view.tag;
    
    if(_hasBadgeTapEvent && [_eventDelegate respondsToSelector:@selector(tableView:didTapCellBadge:)])
    {
        [_eventDelegate tableView:self didTapCellBadge:(KATTableCell *)[_cellArray get:(int)recognizer.view.tag]];
    }
}



#pragma -mark 文本编辑代理

//文本是否可以开始编辑
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    if(_eventDelegate && [_eventDelegate respondsToSelector:@selector(tableView:shouldStartEditingTextInCell:)])
    {
        return [_eventDelegate tableView:self shouldStartEditingTextInCell:(KATTableCell *)[_cellArray get:(int)textView.tag]];
    }
    
    return YES;
}


//文本开始编辑
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if(_eventDelegate && [_eventDelegate respondsToSelector:@selector(tableView:didStartEditingTextInCell:)])
    {
        [_eventDelegate tableView:self didStartEditingTextInCell:(KATTableCell *)[_cellArray get:(int)textView.tag]];
    }
}


//文本完成编辑
- (void)textViewDidEndEditing:(UITextView *)textView
{
    if(_eventDelegate && [_eventDelegate respondsToSelector:@selector(tableView:didFinishEditingTextInCell:)])
    {
        [_eventDelegate tableView:self didFinishEditingTextInCell:(KATTableCell *)[_cellArray get:(int)textView.tag]];
    }
}


//文本是否改变内容
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if(_eventDelegate && [_eventDelegate respondsToSelector:@selector(tableView:shouldChangeText:inCell:)])
    {
        return [_eventDelegate tableView:self shouldChangeText:text inCell:(KATTableCell *)[_cellArray get:(int)textView.tag]];
    }
    
    return YES;
}


//文本改变内容
- (void)textViewDidChange:(UITextView *)textView
{
    //改变内容
    KATTableCellData *data=((KATTableCell *)[_cellArray get:(int)textView.tag]).data;
    data.text=textView.text;
    
    if(_eventDelegate && [_eventDelegate respondsToSelector:@selector(tableView:didChangeTextInCell:)])
    {
        [_eventDelegate tableView:self didChangeTextInCell:(KATTableCell *)[_cellArray get:(int)textView.tag]];
    }
}


//从父视图中移除时，关闭定时器
- (void)removeFromSuperview
{
    [super removeFromSuperview];
    
    if(_remoteImageUpdateTimer)//取消定时器
    {
        [_remoteImageUpdateTimer invalidate];
        [_remoteImageUpdateTimer release];
        _remoteImageUpdateTimer=nil;
        
        _isRemoteImageUpdateTimerWorking=NO;
    }
}



- (void)dealloc
{
    if(_remoteImageUpdateTimer)//取消定时器
    {
        [_remoteImageUpdateTimer invalidate];
        [_remoteImageUpdateTimer release];
        _remoteImageUpdateTimer=nil;
        
        _isRemoteImageUpdateTimerWorking=NO;
    }
    
    dispatch_release(_queueImage);
    dispatch_release(_queueImage2);
    dispatch_release(_queueImage3);
    
    [_scrollView release];
    [_cellArray release];
    [_dataArray release];
    [_builder release];
    [_backBgColor release];
    [_midBgColor release];
    [_faceBgColor release];
    [_cacheImage release];
    [_line1Color release];
    [_line2Color release];
    [_topLineColor release];
    [_bottomLineColor release];
    [_titleColor release];
    [_titleFont release];
    [_contentColor release];
    [_contentFont release];
    [_textBgColor release];
    [_textBorderColor release];
    [_textColor release];
    [_textFont release];
    [_richTitleStyle release];
    [_richContentStyle release];
    [_richLabelStyle release];
    [_label1Color release];
    [_label1Font release];
    [_label2Color release];
    [_label2Font release];
    [_label3Color release];
    [_label3Font release];
    [_label4Color release];
    [_label4Font release];
    [_label5Color release];
    [_label5Font release];
    [_badgeFont release];
    [_badgeBgColor release];
    [_badgeTextColor release];
    [_badgeBorderColor release];
    [_button1Color release];
    [_button2Color release];
    [_button3Color release];
    [_backButton1Color release];
    [_backButton2Color release];
    [_backButton3Color release];
    [_backButton4Color release];
    [_backButton5Color release];
    [_backButton6Color release];
    [_backButton7Color release];
    [_backLabelColor release];
    [_backLabelFont release];
    [_pullHeader release];
    [_pushFooter release];
    [_noneDataTipsLabel release];
    [_strNoneDataTips release];
    [_noneDataTipsTextColor release];
    [_noneDateTipsTextFont release];
    [_tapedBgColor release];
    [_tapedButtonColor release];
    [_tapedTextColor release];
    [_tapedFaceLayerColor release];
    
    [super dealloc];
}


@end
